MFC InitInstance deadlock

  • Thread starter Thread starter Bruno van Dooren
  • Start date Start date
B

Bruno van Dooren

Hi,

i am developing a dll that uses MFC.
i have implemented the initinstance method for initializing my dll

when i try to start a worker thread with AfxBeginThread, the program hangs.

if i try to start it from a regular exported function, there is no problem.

I looked in the MSDN documentation for AfxBeginThread and InitInstance, and
there is no
indication that it is illegal to start a new thread from the initinstance
method.

am i doing something wrong?

kind regards,
Bruno.
 
Bruno van Dooren said:
i am developing a dll that uses MFC.
i have implemented the initinstance method for initializing my dll

when i try to start a worker thread with AfxBeginThread, the program hangs.

if i try to start it from a regular exported function, there is no problem.

I looked in the MSDN documentation for AfxBeginThread and InitInstance, and
there is no
indication that it is illegal to start a new thread from the initinstance
method.

Take a look at this:

http://support.microsoft.com/default.aspx?scid=kb;EN-US;142243
am i doing something wrong?

Yes. :-) The article has an MFC slant, but the general rule is that you
should not do much while processing a DLL_PROCESS_ATTACH notification which
is where MFC invokes your initer.

In fact, the system serializes all DLL notificaitions so you should never do
anything that results in another notification. In your case that is the
DLL_THREAD_ATTACH notification that comes of creating a new thread.

I believe the issue is discusses in greater detail in the help entry for
LoadLibrary() and in the overview of DLLs and threads.

Regards,
Will
 
Back
Top