?
Solved

Modless dialog quandary

Posted on 2002-06-18
7
Medium Priority
?
257 Views
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?
0
Comment
Question by:alan93
[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
  • 2
  • 2
7 Comments
 
LVL 16

Expert Comment

by:AlexNek
ID: 7090114
2 alan93
did you use in DLL the next line?
AFX_MANAGE_STATE(AfxGetStaticModuleState());

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.
0
 

Author Comment

by:alan93
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
       else
           MessageBox("Bad pointer to function in DLL","5",MB_ICONHAND);

          FreeLibrary(hLib);
     }
    else{
          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.

0
 
LVL 16

Expert Comment

by:AlexNek
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);
0
Percona Live Europe 2017 | Sep 25 - 27, 2017

The Percona Live Open Source Database Conference Europe 2017 is the premier event for the diverse and active European open source database community, as well as businesses that develop and use open source database software.

 
LVL 12

Accepted Solution

by:
migel earned 1200 total points
ID: 7091886
Hi!
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.
0
 

Author Comment

by:alan93
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?
0
 
LVL 12

Expert Comment

by:migel
ID: 7092817
Hi!
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.
0
 

Author Comment

by:alan93
ID: 7092825
Great thanks
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

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…
Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
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.
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
Suggested Courses

762 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