CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 11 of 11

Threaded View

  1. #1
    Join Date
    Jan 2009
    Posts
    3

    DLL EntryPoint - Problem

    Hi!
    For some reason, my dll entryPoint doesn't enter to "DLL_THREAD_DETACH"
    and because of that i cant close the threads i opened.

    i am using these functions (taken from a class):
    Code:
    void myThread::startThread()
    {
    	this->stopFlag = CreateEvent(NULL,false,false,L"myEvent");
    	CreateThread(NULL,NULL,&myThread::threadProc,this,0,NULL);
    }
    void myThread::endThread()
    {
    	SetEvent(this->stopFlag);
    	CloseHandle(this->stopFlag);
    	CloseHandle(this->threadHandle);
    }
    void myThread::startMonitor()
    {
    	while(true)
    	{
    		Sleep(2000);
    		if (WAIT_OBJECT_0 == WaitForSingleObject(this->stopFlag,0))
    			break;
    	}
    	
    }
    DWORD WINAPI myThread::threadProc(LPVOID param)
    {
    	myThread* tmp = (myThread*)param;
    	tmp->startMonitor();
    	return 0;
    }
    
    and the entryPoint:
    
    myThread _monitor;
    BOOL APIENTRY DllMain( HMODULE hModule,
                           DWORD  ul_reason_for_call,
                           LPVOID lpReserved
    					 )
    {
    	switch (ul_reason_for_call)
    	{
    	case DLL_PROCESS_ATTACH:
    		_monitor.startThread();
    		break;
    	case DLL_THREAD_DETACH:
    		_monitor.endThread();
    		break;
    	case DLL_PROCESS_DETACH:
    		break;
    	}
    	return TRUE;
    }
    i cant get to the "_monitor.endThread()" function.

    tnx for the help and sorry for the lame english.
    Last edited by Andreas Masur; January 10th, 2009 at 10:00 AM. Reason: Added code tags...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured