Solved

Modless dialog quandary

Posted on 2002-06-18
7
252 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
  • 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 12

Accepted Solution

by:
migel earned 300 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
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 is a video that shows how the OnPage alerts system integrates into ConnectWise, how a trigger is set, how a page is sent via the trigger, and how the SENT, DELIVERED, READ & REPLIED receipts get entered into the internal tab of the ConnectWise …

914 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

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now