Solved

MFC DLLs

Posted on 2001-09-03
9
930 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
ID: 6449930
have you got an AFX_MANAGE_STATE macro in there?
0
 
LVL 1

Author Comment

by:PC-Alex
ID: 6449944
Shaun,

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

Expert Comment

by:Vider
ID: 6450253
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
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 9

Expert Comment

by:ShaunWilde
ID: 6450363
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
 
LVL 1

Author Comment

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

Accepted Solution

by:
PC-Alex earned 0 total points
ID: 6450986
0
 
LVL 4

Expert Comment

by:jtwine100697
ID: 6453067
> _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
ID: 9531982
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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Decoding 32 bit binary streams 6 49
Add content to output file 4 67
difference between String.subString() and String.subSequence() 6 234
I could not set window to top 4 20
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: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
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.
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

860 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