Click here to Skip to main content
15,898,035 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: STL container of multiple types Pin
Todd Smith31-Jul-01 5:52
Todd Smith31-Jul-01 5:52 
QuestionHow can I move mouse cursor from my program? Pin
30-Jul-01 14:21
suss30-Jul-01 14:21 
AnswerRe: How can I move mouse cursor from my program? Pin
Carlos Antollini30-Jul-01 15:47
Carlos Antollini30-Jul-01 15:47 
GeneralDisabling Keys Pin
Orbitalne30-Jul-01 12:23
Orbitalne30-Jul-01 12:23 
GeneralRe: Disabling Keys Pin
Matt.W.30-Jul-01 15:47
Matt.W.30-Jul-01 15:47 
GeneralRe: Disabling Keys Pin
31-Jul-01 4:52
suss31-Jul-01 4:52 
Generalpalmap32.dll <-pretty impossible !?! Pin
30-Jul-01 11:42
suss30-Jul-01 11:42 
GeneralSynchronizing a global function Pin
PJ Arends30-Jul-01 11:37
professionalPJ Arends30-Jul-01 11:37 
Hi, I'm hoping someone here can help me with a synchronization question.
I have a global function that adds entries to a log file. This function can be accessed by several threads in my program, and this function will also be used in different programs to write to the same log file. Because the log file is opened with the CFile::shareDenyWrite flag, I can only allow one thread to have access to this function at one time.
////////////////////////////////////////////////////////////////////////////
// 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.

void WriteLog (LPCTSTR EntryString)
{
    CMutex mutex(FALSE, _T("WriteLog - {AE4E28C0-84E6-11d5-B625-F80C283F7922}"));
    CSingleLock lock(&mutex, FALSE);
    while (lock.IsLocked());    // wait for this function to be free
    lock.Lock();                // deny other threads access
    COleDateTime dt = COleDateTime::GetCurrentTime();
    CString LogEntry = dt.Format("%d/%m/%y %H:%M:%S - ");
    LogEntry += EntryString;
    CRotatingLog rl(_T("C:\\Bird_Log.txt"), 1000, 100);
    rl.AddLine(LogEntry);
}
As this is the first time I am using this method, I would like to know if this is the correct way of doing this, or will this just give me problems in the future? Is there a better way to wait for the CSingleLock object to unlock? The while loop seems to be very processor intensive. Any advice appreciated.
TIA

---
Multitasking: Screwing up several things at once.
GeneralRe: Synchronizing a global function Pin
Tomasz Sowinski30-Jul-01 11:42
Tomasz Sowinski30-Jul-01 11:42 
GeneralRe: Synchronizing a global function Pin
PJ Arends30-Jul-01 11:44
professionalPJ Arends30-Jul-01 11:44 
GeneralDegree to pixel Pin
Not Active30-Jul-01 11:26
mentorNot Active30-Jul-01 11:26 
GeneralRe: Degree to pixel Pin
Tomasz Sowinski30-Jul-01 11:47
Tomasz Sowinski30-Jul-01 11:47 
GeneralRe: Degree to pixel Pin
Wolfram Steinke30-Jul-01 11:49
Wolfram Steinke30-Jul-01 11:49 
GeneralUDP Socket Pin
orcun colak30-Jul-01 10:37
orcun colak30-Jul-01 10:37 
GeneralRe: UDP Socket Pin
EiSl2-Aug-01 1:52
EiSl2-Aug-01 1:52 
Generalmultirow buttons in CToolBar Pin
gaylen30-Jul-01 9:55
gaylen30-Jul-01 9:55 
GeneralRe: multirow buttons in CToolBar Pin
EiSl2-Aug-01 1:55
EiSl2-Aug-01 1:55 
GeneralEncryption Pin
Frank Deo30-Jul-01 9:48
Frank Deo30-Jul-01 9:48 
GeneralRe: Encryption Pin
Joaquín M López Muñoz30-Jul-01 11:46
Joaquín M López Muñoz30-Jul-01 11:46 
GeneralRe: Encryption Pin
Frank Deo30-Jul-01 12:31
Frank Deo30-Jul-01 12:31 
QuestionHow can I create read-only file ??? Pin
30-Jul-01 9:45
suss30-Jul-01 9:45 
AnswerRe: How can I create read-only file ??? Pin
Carlos Antollini30-Jul-01 10:09
Carlos Antollini30-Jul-01 10:09 
AnswerRe: How can I create read-only file ??? Pin
Hadi Rezaee30-Jul-01 19:28
Hadi Rezaee30-Jul-01 19:28 
QuestionCan a CRuntimeClass be Serialized? Pin
Joel Holdsworth30-Jul-01 9:22
Joel Holdsworth30-Jul-01 9:22 
AnswerRe: Can a CRuntimeClass be Serialized? Pin
Tomasz Sowinski30-Jul-01 9:27
Tomasz Sowinski30-Jul-01 9:27 

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.