Subj : threading problem in dll??? Help needed badly. To : comp.programming.threads From : chuayongquan Date : Thu Jul 07 2005 12:13 am thread function: UINT abc::abcfunction(LPVOID pParam) { abc* pCM = (abc*)pParam; ::CoInitialize(NULL); while (1) { TryEnterCriticalSection(CS); // my thread code here if (stopthread){ LeaveCriticalSection(CS); break; } LeaveCriticalSection(CS); } ::CoUninitialize(); return 0; } //end thread function init thread: m_pThread = AfxBeginThread(abcfunction, this); m_pThread->m_bAutoDelete = false; //end init the problem comes when i am going to stop the thread in the dll stop thread function: TryEnterCriticalSection(CS); stopthread = true; LeaveCriticalSection(CS); if ( m_pThread ) { WaitForSingleObject( m_pThread->m_hThread, 5000 ); delete m_pThread; m_pThread = NULL; } //end stop thread my vs c++ debugger always come up with memory leak detected and start to dump object, what frustrate me is that it didn't indicate any line no. and function name even thought I have put _CrtDumpMemoryLeaks (). the problem also something say access violation @ kernel.dll or ntdll.dll. can someone help me, i am stuck for about 3 weeks at this problem thx... .