Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Thread is not going to the Function

Thread is not going to the Function

Scheduled Pinned Locked Moved C / C++ / MFC
databasecomquestion
4 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    aman2006
    wrote on last edited by
    #1

    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

    D 1 Reply Last reply
    0
    • A aman2006

      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

      D Offline
      D Offline
      David Crow
      wrote on last edited by
      #2

      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

      A 1 Reply Last reply
      0
      • D David Crow

        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

        A Offline
        A Offline
        aman2006
        wrote on last edited by
        #3

        I am putting the Break Point in the ThreadFunc() but it is not going to that function. Shailesh

        D 1 Reply Last reply
        0
        • A aman2006

          I am putting the Break Point in the ThreadFunc() but it is not going to that function. Shailesh

          D Offline
          D Offline
          David Crow
          wrote on last edited by
          #4

          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

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups