CreateThread is not Calling the function in DLL
-
HI I am writing a DLL in which i am creating a thread like this: extern "C" __declspec(dllexport) BOOL ReadCard(char *pData) { if(g_hPort == NULL) { strcpy(pData,"COM port is not opened"); return false; } g_hThreadRead = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)ThreadFunc, 0, 0 ,&dwThreadID); return true; } This create thread function is suppose to go to ThreadFunc() but it is not going . can any body give me some suggestion why it is not going to ThreadFunc() DWORD WINAPI ThreadFunc(LPVOID pData) { BOOL bSuccess = TRUE; while(1) { int index = 0; // Clear the dara buffer first. memset(g_strResult,0x00,500); if ( l_bTaskAbort ) { Disconnect(); return(false); } //if card is seated // Ask the user to remove the card // if the card is removed then read the data if(GetCardData()) { //MyMSR_ShowResult(0); strcpy((char*)pData,g_strResult); break; } } return bSuccess; } Thanks in advance shailesh
-
HI I am writing a DLL in which i am creating a thread like this: extern "C" __declspec(dllexport) BOOL ReadCard(char *pData) { if(g_hPort == NULL) { strcpy(pData,"COM port is not opened"); return false; } g_hThreadRead = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)ThreadFunc, 0, 0 ,&dwThreadID); return true; } This create thread function is suppose to go to ThreadFunc() but it is not going . can any body give me some suggestion why it is not going to ThreadFunc() DWORD WINAPI ThreadFunc(LPVOID pData) { BOOL bSuccess = TRUE; while(1) { int index = 0; // Clear the dara buffer first. memset(g_strResult,0x00,500); if ( l_bTaskAbort ) { Disconnect(); return(false); } //if card is seated // Ask the user to remove the card // if the card is removed then read the data if(GetCardData()) { //MyMSR_ShowResult(0); strcpy((char*)pData,g_strResult); break; } } return bSuccess; } Thanks in advance shailesh
Why aren't you checking the return value from CreateThread? If a NULL is returned, GetLastError will return information on why it failed. It can't hurt to try that. Also, try to avoid using (LPTHREAD_START_ROUTINE) cast. If you can't use the routine name without the cast, then chances are your routine is declared wrong and the thread might fail in strange ways. Tim Smith I'm going to patent thought. I have yet to see any prior art.
-
Why aren't you checking the return value from CreateThread? If a NULL is returned, GetLastError will return information on why it failed. It can't hurt to try that. Also, try to avoid using (LPTHREAD_START_ROUTINE) cast. If you can't use the routine name without the cast, then chances are your routine is declared wrong and the thread might fail in strange ways. Tim Smith I'm going to patent thought. I have yet to see any prior art.