Modless dialog quandary

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?
Who is Participating?
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.
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.
alan93Author Commented:
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.

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

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);
alan93Author Commented:
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?
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.
alan93Author Commented:
Great thanks
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.