Hi, I post my problem in Slow Chat thread http://www.codeguru.com/forum/showthread.php?t=496443. Thank you for all your answers. As MikeAThon wrote - that I can't block InitInstance function of CWinThread class. So my question is - where should I put my mainLoop() function in my custom thread? OnIdle ? And one more question: I tried to add CList object to my thread as a message list. From main thread I'm adding new messages to that list. And in my thread I would like to get the message objects from that list. I surrounded all operation on that list with CriticalSection. But it's not working - some heap errors appears. is it possible to share CList objects between threads, in one thread create objects by new operator and add it to list, and in another thread gets it from list and deleteing by delete ?
Code:
void CMessageQueue::sendMessage( MessageStruct *mess ) {
if ( mess != NULL ) {
EnterCriticalSection( &critSection );
queue.AddTail( mess );
LeaveCriticalSection( &critSection );
}
}
//////////////////////////////////////////////////////////////////////////
MessageStruct *CMessageQueue::receiveMessage() {
MessageStruct *mes = NULL;
if ( getMessageCount() > 0 ) {
EnterCriticalSection( &critSection );
mes = queue.RemoveTail();
LeaveCriticalSection( &critSection );
}
return mes;
}
//////////////////////////////////////////////////////////////////////////
int CMessageQueue::getMessageCount() {
int count = 0x00;
EnterCriticalSection( &critSection );
count = queue.GetCount();
LeaveCriticalSection( &critSection );
return count;
}