MFC DLLs

I'm using an MFC DLL, which cannot open a CDialog with DoModal(); MFC throws an assert, because the AFX - thread seems to be NULL.

The DLL has the options "Use MFC in a static library", the compiler switches _MT, _WINDLL and _USRDLL are defined. The runtime library is "Debug multithreaded".

A routine is called from my main application, and the main thread (CWinApp) from there wants to open a Dialog with DoModal. I can step into AfxGetThread(), and there I see that the CurrentWinThread (from the ModulThreadState) is NULL, and then AfxGetApp() also yields NULL.

How can I tell the DLL that its thread is the one from the calling application ?
LVL 1
PC-AlexAsked:
Who is Participating?
 
PC-AlexConnect With a Mentor Author Commented:
0
 
ShaunWildeCommented:
have you got an AFX_MANAGE_STATE macro in there?
0
 
PC-AlexAuthor Commented:
Shaun,

where ? In the DLL, in my code ? No.
0
Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

 
ViderCommented:
Make sure you call the rutine after the InitInstance() of your library,

And include this in the first line of your function:
bool mylib::myfunc() {
   AFX_MANAGE_STATE(AfxGetStaticModuleState())
...
}

this macro will manage the changes betwen threads in your app setting local resources, etc.

Regards,
Vider
0
 
ShaunWildeCommented:
Vider - please retract your answer - you're only expanding on a previous comment - please read the following EE guidlines - http://www.experts-exchange.com/jsp/cmtyQuestAnswer.jsp 
0
 
PC-AlexAuthor Commented:
No, Vider, this didn't help.
0
 
jtwine100697Commented:
> _USRDLL

As you already discovered, "_USRDLL" was a hint to your problem (and should have been to everyone else, IMHO).  _USERDLL's normally require that their own CWinApp object be instantiated in the DLL.

-=- James.
0
 
Roshan DavisCommented:
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:

PAQ'd and pts refunded

Please leave any comments here within the next seven days.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

Roshan Davis
EE Cleanup Volunteer
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.