Modless dialog quandary

Posted on 2002-06-18
Last Modified: 2013-11-20
I have a dll dialog that has a function that pops up a modless dialog (using a class called CPictureDlg). I'm using the CDialog::Create() and the ShowWindow() to do this.

It works fine, while the dll dialog is loaded.

What I was wanting to do is export that CPictureDlg to the calling exe.

I can get it to work calling DoModal() but not with the Create().

The problem is somewhere with the Create params I guess.

I've tried leaving the CWnd* null and I've tried GetActiveWindow(), and I've tried passing the parent *wnd from the exe but always get some sort of error like "memory could not be read".

Is there a way to do this?
Question by:alan93
  • 3
  • 2
  • 2
LVL 16

Expert Comment

ID: 7090114
2 alan93
did you use in DLL the next line?

It can be a problem too where you create the windows. You must create both parent and dlg in exe. Or you can export the whole CPictureDlg class.

Author Comment

ID: 7090227
no i didn't , I tried it and same result.
Here's what I have in DLL:

extern "C" MyDLL int __cdecl PictureView( LPSTR lpsPictureFile)
     CPartView *PictureDlg = new CPictureDlg;

     PictureDlg ->m_csImageName = lpsPictureFile;
     PictureDlg ->Create(IDD_PICTUREVIEW_DIALOG);    
     PictureDlg ->ShowWindow(SW_SHOW);

       return 0;

The the calling app:
void CMyView::DisplayPicture(


    hLib = LoadLibrary(csLibPath);  
    if (hLib != NULL){
       lpFunc = (FPPLocal)GetProcAddress(hLib,"PictureView");
       if (lpFunc!=NULL)
            (*lpFunc)( pImg );                         //Call Exported DLL function
           MessageBox("Bad pointer to function in DLL","5",MB_ICONHAND);

          csError = "Could not find MyDll.DLL ";
          MessageBox(csError,"ProjectSpec",MB_OK | MB_ICONEXCLAMATION);

If I do it as DoModal() it works.
The Modeless works fine in another function in the DLL WHILE the dll is loaded.

LVL 16

Expert Comment

ID: 7090930
2 alan93
>works fine in another function in the DLL WHILE the dll is loaded.
What are you expected? You need to close modeless dialog when dll is unloaded. You can try to binding via lib file.

extern "C" __declspec( dllexport ) int PictureView( LPSTR lpsPictureFile);
Active Directory Webinar

We all know we need to protect and secure our privileges, but where to start? Join Experts Exchange and ManageEngine on Tuesday, April 11, 2017 10:00 AM PDT to learn how to track and secure privileged users in Active Directory.

LVL 12

Accepted Solution

migel earned 300 total points
ID: 7091886
You free library just immidiatelly after create dialog - it is bad thing  since dialog procedure stored in the DLL and during Library freing your dialog must be destoyed.

Store DLL handle in the main APP class ad  call FreeLibrary before APP exit.

Author Comment

ID: 7092693
2 AlexNek
Not sure what you mean exactly by 'binding'. What, how?

2 Migel
Makes sense, I commented out the  FreeLibrary(hLib) just to temporarily test and it works.

But what if there are multiple calls to the DisplayPicture() function, I may be stupid here, but is there a problem with this statement if that happens?
hLib = LoadLibrary(csLibPath);  

If I free hLib on App exit, does it free all libraries loaded?
LVL 12

Expert Comment

ID: 7092817
Multiply call LoadLibrary doesn`t load multiple copies of the DLL. DLL IMAGEmapped into the process address space  at the first call, all subsicuent calls just returns existing HANDLE and increment usage count of the library.
UMHO you have to load this library at APP start and free at APP end.

Author Comment

ID: 7092825
Great thanks

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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

Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
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.
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

830 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