Solved

Modless dialog quandary

Posted on 2002-06-18
7
251 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 12

Accepted Solution

by:
migel earned 300 total points
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
Great thanks
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Suggested Solutions

Introduction: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
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.
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.

772 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

10 Experts available now in Live!

Get 1:1 Help Now