MFC InitInstance deadlock

  • Thread starter Bruno van Dooren
  • 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.
 
W

William DePalo [MVP]

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top