unable to call a thread in dll file

前端 未结 1 535
慢半拍i
慢半拍i 2021-02-09 17:37

I am trying to create a dll which will create a thread when you load him for some reason the thread function is not doing anything.. :\\

this is my code:

dllthre

1条回答
  •  长发绾君心
    2021-02-09 18:20

    Instead of starting the thread from DllMain() export a function that would launch the thread instead:

    extern "C" __declspec(dllexport) void start_thread()
    {
        DWORD DllThreadID;
        HANDLE DllThread; //thread's handle
    
        DllThread=CreateThread(NULL,0,ThreadProc,0,0,&DllThreadID);
        if (DllThread == NULL)
            MessageBox(NULL, L"Error", L"Error", MB_OK);
        else
            CloseHandle(DllThread);
    
    }
    

    After calling LoadLibrary() use GetProcAddress() to get access to the start_thread() function.

    Hope this helps.

    0 讨论(0)
提交回复
热议问题