Solved

MFC DLLs

Posted on 2001-09-03
9
929 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
Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

 
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

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Windows Drag & Drop Location 2 100
Folder Comparison 12 54
How to know only "File created" with EventLog 3 34
fix34  challenge 9 120
This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
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.
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

777 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