Click here to Skip to main content
16,005,473 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralAbout "__stdcall" and "__cdecl" Pin
Maer72729-Aug-01 17:17
Maer72729-Aug-01 17:17 
GeneralRe: About Pin
Michael Dunn29-Aug-01 18:37
sitebuilderMichael Dunn29-Aug-01 18:37 
GeneralRe: About Pin
Maer72729-Aug-01 22:07
Maer72729-Aug-01 22:07 
GeneralCList/CArray duplicate link problem Pin
Wayne Janaway29-Aug-01 15:52
Wayne Janaway29-Aug-01 15:52 
GeneralRe: CList/CArray duplicate link problem Pin
Tomasz Sowinski30-Aug-01 1:24
Tomasz Sowinski30-Aug-01 1:24 
GeneralRe: CList/CArray duplicate link problem Pin
Wayne Janaway30-Aug-01 11:14
Wayne Janaway30-Aug-01 11:14 
GeneralRe: CList/CArray duplicate link problem Pin
Tomasz Sowinski30-Aug-01 11:21
Tomasz Sowinski30-Aug-01 11:21 
GeneralWait for worker thread to finish Pin
PJ Arends29-Aug-01 15:19
professionalPJ Arends29-Aug-01 15:19 
How do I wait for a worker thread to finish? I am trying to use WaitForSingleObject(), waiting on the thread handle, but it does not want to wait for the thread to finish. What else can I use? Or am I approaching this all wrong?
In my dialog based app's InitInstance() function I have this code
...
    dlg.DoModal();

    CWinThread *pThread = WriteLog (_T("GetSamples : Done"));
    TRACE ("Wait for thread at 0x%08X\n", pThread);
    WaitForSingleObject(pThread->m_hThread, WAIT_OBJECT_0);
    TRACE ("Exiting\n");
    return FALSE;
}


Here is my WriteLog() function
////////////////////////////////////////////////////////////////////////////
// WriteLog - writes the 'EntryString' log entry to the 'Bird_Log.txt' log file
// with a date and time stamp. 'EntryString' will be truncated to 80 characters.
// Uses a CMutex and CSingleLock to ensure only one thread at a time has access
// to the log file

UINT WriteLogThreadFunction(LPVOID lp)
{
    TRACE ("WriteLogThreadFunc() Start\n");
    LPTSTR LogEntry = (LPTSTR)lp;
    CMutex mutex(FALSE, _T("WriteLog - {AE4E28C0-84E6-11d5-B625-F80C283F7922}"));
    CSingleLock lock(&mutex, FALSE);
    lock.Lock();
    CRotatingLog rl(_T("C:\\Bird_Log.txt"), 500, 100);
    rl.AddLine(LogEntry);
    delete[] LogEntry;
    TRACE ("WriteLogThreadFunc() End\n");
    return 0;
}

CWinThread* WriteLog (LPCTSTR EntryString)
{
    COleDateTime dt = COleDateTime::GetCurrentTime();
    CString LogEntry = dt.Format("%d/%m/%y %H:%M:%S - ");
#ifdef _DEBUG
    LogEntry += _T("DEBUG - ");
#endif
    LogEntry += EntryString;
    LPTSTR String = new TCHAR[LogEntry.GetLength() + 1];
    _tcscpy(String, LogEntry);
    TRACE ("Starting WriteLogThreadFunc()\n");
    return AfxBeginThread(WriteLogThreadFunction, (LPVOID)String);
}


And here is the debug output
Starting WriteLogThreadFunc()
Wait for thread at 0x00771CC0
Exiting
The thread 0xFFF552F3 has exited with code -1 (0xFFFFFFFF).
Detected memory leaks!
Dumping objects ->
thrdcore.cpp(166) : {4004} client block at 0x00771CC0, subtype 0, 112 bytes long.
a CWinThread object at $00771CC0, 112 bytes long
{4003} normal block at 0x00771820, 46 bytes long.
 Data: <29/08/01 17:12:3> 32 39 2F 30 38 2F 30 31 20 31 37 3A 31 32 3A 33 
Object dump complete.
The thread 0xFFF5443B has exited with code 2 (0x2).

TIA
Pete

---
Multitasking: Screwing up several things at once.
GeneralRe: Wait for worker thread to finish Pin
Not Active29-Aug-01 16:00
mentorNot Active29-Aug-01 16:00 
GeneralRe: Wait for worker thread to finish Pin
Kelly Herald30-Aug-01 10:25
Kelly Herald30-Aug-01 10:25 
GeneralATL Objects Pin
Bret Faller29-Aug-01 13:55
Bret Faller29-Aug-01 13:55 
GeneralRe: ATL Objects Pin
Aaron Schaefer30-Aug-01 4:20
Aaron Schaefer30-Aug-01 4:20 
GeneralInternet link on my about dialog box Pin
Jonathan Craig29-Aug-01 13:42
Jonathan Craig29-Aug-01 13:42 
GeneralRe: Internet link on my about dialog box Pin
Jim A. Johnson29-Aug-01 13:59
Jim A. Johnson29-Aug-01 13:59 
GeneralRe: Internet link on my about dialog box Pin
Not Active29-Aug-01 14:10
mentorNot Active29-Aug-01 14:10 
GeneralNM_RETURN vs NM_CLICK Pin
29-Aug-01 11:23
suss29-Aug-01 11:23 
GeneralRe: NM_RETURN vs NM_CLICK Pin
Joaquín M López Muñoz29-Aug-01 20:17
Joaquín M López Muñoz29-Aug-01 20:17 
GeneralC++ control to ActiveX and C++ control to DLL Pin
29-Aug-01 11:11
suss29-Aug-01 11:11 
GeneralRe: C++ control to ActiveX and C++ control to DLL Pin
29-Aug-01 11:20
suss29-Aug-01 11:20 
GeneralRe: C++ control to ActiveX and C++ control to DLL Pin
29-Aug-01 11:55
suss29-Aug-01 11:55 
GeneralListBox Control Pin
RobJones29-Aug-01 9:42
RobJones29-Aug-01 9:42 
GeneralRe: ListBox Control Pin
Not Active29-Aug-01 14:18
mentorNot Active29-Aug-01 14:18 
GeneralRe: ListBox Control Pin
Michael Dunn29-Aug-01 14:30
sitebuilderMichael Dunn29-Aug-01 14:30 
GeneralRe: ListBox Control Pin
RobJones30-Aug-01 4:58
RobJones30-Aug-01 4:58 
GeneralOwner draw static control and memory leak Pin
Peter Pearson29-Aug-01 9:38
Peter Pearson29-Aug-01 9:38 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.