When using the following stripped-down multithreaded code in CVI 5.5.1
the OpenCom() function crashes when the thread is executed for the
second time. It only works if I remove the GetSystemComHandle() call.
Any comments, suggestions?
Thanks, Marcel
#include
#include
#include
HANDLE ThreadHandle;
int ThreadID;
HANDLE ComHandle;
DWORD WINAPI ComThread(LPVOID Param)
{
OpenCom(1, "");
GetSystemComHandle(1, (int*)&ComHandle);
CloseCom(1);
return 1;
}
int main(int argc, char *argv[])
{
if (InitCVIRTE(0, argv, 0) == 0)
return -1;
ThreadHandle = CreateThread(NULL, 0, ComThread, 0, 0, &ThreadID);
WaitForSingleObject(ThreadHandle, INFINITE);
ThreadHandle
= CreateThread(NULL, 0, ComThread, 0, 0, &ThreadID);
WaitForSingleObject(ThreadHandle, INFINITE);
CloseCVIRTE();
return 0;
}