Cannot get thread ID with Thread.getThis() in specific callback functions on Windows
Haruki Shigemori
rayerd.wiz at gmail.com
Sun Dec 5 19:38:40 PST 2010
Hi.
I cannot get thread ID with Thread.getThis() in specific callback
functions on Windows.
What is the cause of this problem?
import win32.windows;
import win32.mmsystem;
import std.stdio;
import core.thread;
extern (Windows)
void waveInProc(in HWAVEIN handle, in uint message, in DWORD instance,
in DWORD param1, in DWORD param2)
{
auto tid = Thread.getThis();
assert(tid); // tid is null
}
void main()
{
WAVEFORMATEX formatEx;
with (formatEx)
{
wFormatTag = WAVE_FORMAT_PCM;
nChannels = 1;
nSamplesPerSec = 44100;
wBitsPerSample = 16;
nBlockAlign = cast(ushort)(wBitsPerSample * nChannels / 8);
nAvgBytesPerSec = nSamplesPerSec * nBlockAlign;
}
HWAVEIN handle;
waveInOpen(&handle, WAVE_MAPPER, cast(WAVEFORMATEX*)&formatEx,
cast(DWORD)&waveInProc, cast(DWORD)null, CALLBACK_FUNCTION);
uint bufferSize = cast(uint)(formatEx.nAvgBytesPerSec *
1/+second+/);
WAVEHDR* hdr = new WAVEHDR;
hdr.lpData = cast(LPSTR)new ushort[bufferSize];
hdr.dwBufferLength = bufferSize;
hdr.dwFlags = 0;
hdr.dwLoops = 0;
waveInPrepareHeader(handle, hdr, WAVEHDR.sizeof);
waveInAddBuffer(handle, hdr, WAVEHDR.sizeof);
waveInStart(handle);
readln();
}
More information about the Digitalmars-d
mailing list