Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 942
  • Last Modified:

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 ?
0
PC-Alex
Asked:
PC-Alex
1 Solution
 
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
 
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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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
 
PC-AlexAuthor Commented:
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

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now