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. CreateThread is not Calling the function in DLL

CreateThread is not Calling the function in DLL

Scheduled Pinned Locked Moved C / C++ / MFC
databasecom
3 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 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

    T 1 Reply Last reply
    0
    • A aman2006

      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

      T Offline
      T Offline
      Tim Smith
      wrote on last edited by
      #2

      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.

      A 1 Reply Last reply
      0
      • T Tim Smith

        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.

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

        I Checked the returned value from CreateThread, it is a handle to the thread but it is not going to the function. Also i Called the GetLastError() after the createthread() function it is returning zero. Any more suggestions... Thanks Shailesh

        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