Thread is not going to the Function
-
Hi Here is my Full code in which i am creating a thread in DLL and passing the function name as ThreadFunc . But it is not going to the ThreadFunc after creating it. See the Func PrepareThread() below BOOL APIENTRY DllMain( HANDLE hModule, DWORD ul_reason_for_call, LPVOID lpReserved ) { return TRUE; } extern "C" __declspec(dllexport) BOOL Connect ( char *pPort , char *pBuff ) { int nDataSize = 0; int nSentSize = 0; if(strcmp(pPort,"") == 0) { strcpy(pBuff,"Please supply a COM port"); return false; } g_hPort = Rs232Open(pPort); if ( l_bTaskAbort ) { Rs232CleanUp(FALSE); return false; } if ( g_hPort == NULL ) { l_dwErrCode = GetLastError(); ShowRegError(l_dwErrCode); Rs232CleanUp(FALSE); return false; } // wake up printer char wakeUpChars[2]; wakeUpChars[0]=(char)'0x0H'; wakeUpChars[1]='\0'; nDataSize = strlen(wakeUpChars); nSentSize = Rs232SendBlk(g_hPort, wakeUpChars, nDataSize); Sleep(100); if ( l_bTaskAbort ) { Rs232CleanUp(FALSE); return(false); } //Lets check for oneil printer attached or not nDataSize = 6; nSentSize = Rs232SendBlk(g_hPort,"\x1b{ST?}",nDataSize); if(nSentSize != nDataSize) return false; // Sleep(100); char szData[36]; memset(szData,0x00,sizeof(szData)); if(Rs232RecvBlk(g_hPort,szData,35 ) >0) { if(strncmp(szData,"{ST!E:N;",8) != 0) { strcpy(pBuff,"Printer is not connected."); return false; } } else { strcpy(pBuff,"Printer is not connected."); return false; } return true; } extern "C" __declspec(dllexport) BOOL ReadCard(char *pData) { if(g_hPort == NULL) { strcpy(pData,"COM port is not opened"); return false; } PrepareThread(); return true; } extern "C" __declspec(dllexport)void Disconnect() { //Terminate Read thread and close msr3000 TerminateThread(g_hThreadRead, 0); g_hThreadRead = NULL; Rs232CleanUp(FALSE); } DWORD WINAPI ThreadFunc(LPVOID param) { 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); break; } } return bSuccess; } static void PrepareThre
-
Hi Here is my Full code in which i am creating a thread in DLL and passing the function name as ThreadFunc . But it is not going to the ThreadFunc after creating it. See the Func PrepareThread() below BOOL APIENTRY DllMain( HANDLE hModule, DWORD ul_reason_for_call, LPVOID lpReserved ) { return TRUE; } extern "C" __declspec(dllexport) BOOL Connect ( char *pPort , char *pBuff ) { int nDataSize = 0; int nSentSize = 0; if(strcmp(pPort,"") == 0) { strcpy(pBuff,"Please supply a COM port"); return false; } g_hPort = Rs232Open(pPort); if ( l_bTaskAbort ) { Rs232CleanUp(FALSE); return false; } if ( g_hPort == NULL ) { l_dwErrCode = GetLastError(); ShowRegError(l_dwErrCode); Rs232CleanUp(FALSE); return false; } // wake up printer char wakeUpChars[2]; wakeUpChars[0]=(char)'0x0H'; wakeUpChars[1]='\0'; nDataSize = strlen(wakeUpChars); nSentSize = Rs232SendBlk(g_hPort, wakeUpChars, nDataSize); Sleep(100); if ( l_bTaskAbort ) { Rs232CleanUp(FALSE); return(false); } //Lets check for oneil printer attached or not nDataSize = 6; nSentSize = Rs232SendBlk(g_hPort,"\x1b{ST?}",nDataSize); if(nSentSize != nDataSize) return false; // Sleep(100); char szData[36]; memset(szData,0x00,sizeof(szData)); if(Rs232RecvBlk(g_hPort,szData,35 ) >0) { if(strncmp(szData,"{ST!E:N;",8) != 0) { strcpy(pBuff,"Printer is not connected."); return false; } } else { strcpy(pBuff,"Printer is not connected."); return false; } return true; } extern "C" __declspec(dllexport) BOOL ReadCard(char *pData) { if(g_hPort == NULL) { strcpy(pData,"COM port is not opened"); return false; } PrepareThread(); return true; } extern "C" __declspec(dllexport)void Disconnect() { //Terminate Read thread and close msr3000 TerminateThread(g_hThreadRead, 0); g_hThreadRead = NULL; Rs232CleanUp(FALSE); } DWORD WINAPI ThreadFunc(LPVOID param) { 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); break; } } return bSuccess; } static void PrepareThre
You'll get much more favorable responses by providing only relevant code. No one likes spending their time wading through code that is not part of the problem. How are you verifying that
ThreadFunc()
is not being called?
"When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen
-
You'll get much more favorable responses by providing only relevant code. No one likes spending their time wading through code that is not part of the problem. How are you verifying that
ThreadFunc()
is not being called?
"When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen
-
I am putting the Break Point in the ThreadFunc() but it is not going to that function. Shailesh
aman2006 wrote: I am putting the Break Point in the ThreadFunc() On the
BOOL bSuccess = TRUE
statement, I assume? If so, could it be possible that the primary thread is terminating before the secondary thread has had a chance to start up?
"When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen