[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

Using a modeless dialog box in a DLL

Posted on 1997-08-27
6
Medium Priority
?
429 Views
Last Modified: 2013-11-20
One of the functions in my DLL takes a while to execute, so I want to add a status box.  The code for the status box works great when used within an exe, but crashes when run within the DLL.

In the DLL, I end up with an access violation whenever I try to Create()
my dialog box.  My best guess is that it has something to do with the
CWnd that it's trying to use for the parent.  When I tried using the
CWnd from AfxGetMainWnd() as the parent, I get the same error.  I'm
thinking that this just means that the default parent for any dialog (if
not specified) is the main window of the app -- just what M.S. claims!

Both the application and the DLL are single threaded.

So... How do I get my modeless box to work ?

0
Comment
Question by:Srw
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
6 Comments
 
LVL 4

Accepted Solution

by:
davmarc earned 200 total points
ID: 1304995
Do you create the dialog box from a dialog template included in your DLL's resources?
If so, did you remember to call AfxSetResourceHandle() passing the HINSTANCE of the DLL module?

Davide Marcato.
0
 
LVL 2

Author Comment

by:Srw
ID: 1304996
The first two lines are the ones I added...
I now get an access violation at the GetInstanceHandle();

HINSTANCE hDLL = AfxGetInstanceHandle();
AfxSetResourceHandle(hDLL);
WaitDialog* pWait = new WaitDialog();

The access violation occured at the final line in this function from Thrdcore.cpp

LRESULT CALLBACK _AfxMsgFilterHook(int code,
                                   WPARAM wParam,
                                   LPARAM lParam)
{ . . .
      return (LRESULT)AfxGetThread()->ProcessMessageFilter(code, (LPMSG)lParam);
}

0
 
LVL 4

Expert Comment

by:davmarc
ID: 1304997
Can you find where exactly the access violation occurs?

Davide Marcato.
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 2

Author Comment

by:Srw
ID: 1304998
Your last question... Where exactly is the exception? got me to thinking.  I'd been using dynamically linked MFC library, and could only get as far as my last answer showed.  So, I tried using the static linked version in the hopes that I might trace down further.  I couldn't even get it to compile -- Linker said it couldn't find '_main'.  I didn't expect to see that message from a DLL!

After a bunch of reading and looking at examples, etc, I realized that I created my DLL as a standard windows DLL, and just wedged MFC in -- all the other stuff it did worked fine...  I decided to create a small test DLL (Using the option MFC DLL) that only creates a modeless dialog.  After solving the crash due to setting the resource handle, it started working! Yea!

The one minor annoyance I encountered was getting the instance handle for my dll. If I tried
HINSTANCE inst = AfxGetInstanceHandle();
and used that, the dll couldn't find the resource.

But, if I added a DLL entry point function and saved the instance that I received, it worked fine.

So, my modeless dialog inside a dll now works!

BTW, is there a better way to get the instance handle?  It just seems slightly inelegant to do it my way.
0
 
LVL 4

Expert Comment

by:davmarc
ID: 1304999
Hmm...AfxGetInstanceHandle() does not work for your DLL, but does it work for the other small testing DLL you created?
If so, maybe you missed something more about turning your DLLinot a fully MFC compliant one.

Davide Marcato.
0
 
LVL 2

Author Comment

by:Srw
ID: 1305000
No, actually AfxGetInstanceHandle appeared to return the instance of the application both times.  The instance handle I used came from
BOOL WINAPI DllEntry(HINSTANCE hInst,
                     ULONG ul_reason_for_call,
                     LPVOID lpReserved)
{
      _dllInst = hInst;
      return TRUE;
}

And I set the linker option: /entry:"DllEntry"

I did all the DLL setup in the CWinApp derived classes's c-tor and d-tor, instead of here.

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.

Question has a verified solution.

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

Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
Ready to get certified? Check out some courses that help you prepare for third-party exams.
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.
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
Suggested Courses

650 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