Click to See Complete Forum and Search --> : using _set_se_translator in multithreaded env


krischk123
May 20th, 2008, 05:11 AM
Hi All



In my project I am trying to convert C exceptions into C++ exceptions using _set_se_translator. I am creating a multithreaded DLL in which the main app thread creates a no. of secondary threads. In the documentation I learnt that we need to register our set_translator functions for each thread.



In my project , each thread that I create has the controlling function(i.e, the function that the thread executes) like the one below:


UINT ControlFunC(LPVOID pvParam)
{
//Register translator function for each read thread
//used to catch aynchronous exceptions
_set_se_translator(SeTranslator);

.....

....

return 0;

}



Also in my main thread , I register _set_se_translator function by putting it in the constructor of the main application objec (which is dreived from CWinApp) like below:


CMainApp::CMainApp()
{
// TODO: add construction code here,
// Place all significant initialization in InitInstance
deviceCount = 0;
printf("\n DLL AppObj Constructor : Inside constructor");
printf("\n DLL AppObj Constructor : About to set translator function");
_set_se_translator(SeTranslator);
}






The translator function simply throws an object of a class that acts as the wrapper class. Is it ok to use the same function SeTranslator for registering my translator function for each thread.



Also , is the way I am refistering set_se_translator for each thread, is it correct, or is there a fault?

Codeplug
May 20th, 2008, 12:01 PM
>> Is it ok to use the same function SeTranslator for registering my translator function for each thread.
Sure. As long as your translator function simply throws a C++ object, as the documentation suggests.

>> is it correct, or is there a fault?
Calling _set_se_translator() on a per-thread basis is ok.

See Reference: http://msdn.microsoft.com/en-us/library/5z4bw5h5(VS.80).aspx

gg