I 开发者_JS百科am using RegisterWaitForSingleObject
to wait on a serial comm events as registered with WaitCommEvent
.
The code works well on Windows XP however always throws an exception somewhere in the treadpool when running on Windows 7.
The stack trace shows
ntdll.dll!_TppWaiterpThread@4() + 0x3a7ee bytes
kernel32.dll!@BaseThreadInitThunk@12() + 0x12 bytes
ntdll.dll!___RtlUserThreadStart@8() + 0x27 bytes
ntdll.dll!__RtlUserThreadStart@8() + 0x1b bytes
Is there any way to get this function to operate correctly in Windows 7 or will I need to re-write with support for the new Windows Vista/7 threadpool functions.
Here is an example of how I am calling the code. As stated this works flawlessly on XP
// Calback is on an object defined as a static function
class CommPortCallback
{
public:
static void WINAPI serialLayerCallback( PVOID lpParameter,
BOOLEAN TimerOrWaitFired )
{
....
}
};
// wait is registered later as such
RegisterWaitForSingleObject(&pWaitData->callbackHandle, m_readOverlapped,
CommPortCallback::serialLayerCallback, pBaseCallback,
INFINITE, WT_EXECUTEONLYONCE)
Show the code calling RegisterWaitForSingleObject
.
At a guess, your callback function has the wrong calling convention or wrong parameter types, you're using a function pointer cast to overrule the compiler's complaint, and then the stack pointer is left misaligned after the call.
With the code the cause is now clear: You're passing in a pointer to the OVERLAPPED
structure, instead of the event handle. It doesn't seem like this should ever have worked correctly on XP, but whether or not it crashes or fails silently could well vary with Windows version.
精彩评论