Solved

MFC DLLs

Posted on 2001-09-03
9
928 Views
Last Modified: 2013-11-20
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
Comment
Question by:PC-Alex
9 Comments
 
LVL 9

Expert Comment

by:ShaunWilde
Comment Utility
have you got an AFX_MANAGE_STATE macro in there?
0
 
LVL 1

Author Comment

by:PC-Alex
Comment Utility
Shaun,

where ? In the DLL, in my code ? No.
0
 

Expert Comment

by:Vider
Comment Utility
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
 
LVL 9

Expert Comment

by:ShaunWilde
Comment Utility
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
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 
LVL 1

Author Comment

by:PC-Alex
Comment Utility
No, Vider, this didn't help.
0
 
LVL 1

Accepted Solution

by:
PC-Alex earned 0 total points
Comment Utility
0
 
LVL 4

Expert Comment

by:jtwine100697
Comment Utility
> _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
 
LVL 23

Expert Comment

by:Roshan Davis
Comment Utility
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Introduction: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

728 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now