Link to home
Start Free TrialLog in
Avatar of rocco
rocco

asked on

Using MFC Dialog in a Win32 DLL

I want to use the U.I. of MFC to create a Dialog Box as
part of a generic win32 DLL.
 
Example: I have a win32 DLL that draws Graphs. I would like
 to be able to configure the graph by making a call to a
 member function of the DLL that pops up a configuration
 dialog.

My crude attempt appears that the DLL resources are not
accessible (DoModal() returns -1). Any suggestions?
Avatar of AVaulin
AVaulin
Flag of Ukraine image

Be sure that you set resource handler to DLL before using dialog resource from this DLL. AfxSetResourceHadle function do this.
Avatar of rocco
rocco

ASKER

I have tried that. It did not make a difference. The DLL
was initial created as a win32 DLL, then adding the shared
MFC library. There seems to be a conflict when _USRDLL is
defined.
Call AFX_MANAGE_STATE(AfxGetStaticModuleState( )) before loading
resources:

// ...
AFX_MANAGE_STATE(AfxGetStaticModuleState( ))
MyDlg dlg;
int ret = dlg.DoModal();
// ...
Avatar of rocco

ASKER

That is true if the class is derived from CWinApp
(MFC dll). In doing so, you will get multiple declared
symbols (_DllMain@12).

I am starting with a generic C++ class (via Win32 dll)
and adding a MFC dialog (CDialog) to provide an GUI
interface. The attempt is to make UI classes separate
from the application classes (in this case the main DLL
class that calls a dialog through a member function.

ASKER CERTIFIED SOLUTION
Avatar of rpb
rpb

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of rocco

ASKER

This sounds like were the problem lies. In order to create a
DLL that support a MFC Dialog, some kind of "App" needs to
be made available. In an extension DLL, the Application's
App class is used. For a regular MFC DLL, the DLL is derived
from CWinApp. Which gets into the reason I work from the Win32
DLL side, keeping the MFC code to a limited area... Any suggestion?