unclepauly 6 Light Poster

hi,

im creating a library, in which there is a winproc that is started in a function called StartMessageLoop. This function is started as a seperate thread from another function called Init. heres the code:

void MyClass::Init()
{
//...some code

_beginthreadex(NULL, 0, StartMessageLoop, (void*)NULL, 0, 0);

WaitForSingleObject(m_VALIDHWNDEVENT, 10000);

//...some mode code
}
unsigned int MyClass::StartMessageLoop(void*)
{
//...some code

/* if the window class is created and registered ok... */
SetEvent(m_VALIDHWNDEVENT);

MSG msg;
while (GetMessage(&msg, NULL, 0, 0)) 
{ 
	TranslateMessage(&msg);
	DispatchMessage (&msg);
}

//...some more code
}

so as you can see, Init waits until it receives the 'window created OK' event from StartMessageLoop before it continues, and then ends.

so my question: if i want the user of my library to be able to catch exceptions that are thrown within the winproc, what would be the best way to do this ?

because the StartMessageLoop function is started as a seperate thread from Init, if the winproc throws an exception, this would bubble up to StartMessageLoop...and then where ? it would not bubble up to Init because Init is on a different thread and has long ended by this point. StartMessageLoop is a private function within my library so the user cannot place a try/catch around this.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.