Solved

Loading Dialog resources in an MFC exe project?

Posted on 2002-07-23
7
747 Views
Last Modified: 2013-11-20
Hello,

I have a dll (say MFC extension dll) which contains dialog resources.
Then I have another MFC app. exe which wants to use the resource dialogs from dll.

What will be the complete steps (from a to z) that will successfully lead me to the solution? Moreover, which type of MFC dll (static, extension etc.) is appropriate for this kind od work?

Thanks in advance for help....

Moreover, let me make it explicit that I have classes against dialogs in the DLL. And I want to use the functions of those classes from the client to manipulate the dialogs...
0
Comment
Question by:Khawar091697
  • 3
  • 2
  • 2
7 Comments
 
LVL 9

Expert Comment

by:BeyondWu
ID: 7173472
1.m_hResourceDLL = AfxLoadLibrary(yourMFCextension.dll)
// if all the resource in this dll, you can call this;
2.AfxSetResourceHandle(m_hResourceDLL);
3.hYourDlg = CreateDialog(m_hResourceDLL,
                      MAKEINTRESOURCE(IDD_YOUR_DIALOGBOX),
                    AfxGetMainWnd()->m_hWnd,
                      (DLGPROC)YourDlgProc);
or
  hYourDlg = CreateDialog(AfxGetResourceHandle( ),
                      MAKEINTRESOURCE(IDD_YOUR_DIALOGBOX),
                    AfxGetMainWnd()->m_hWnd,
                      (DLGPROC)YourDlgProc);
0
 
LVL 9

Expert Comment

by:BeyondWu
ID: 7173474
>>Moreover, which type of MFC dll (static, extension etc.) is appropriate for this kind od work?
I think DLL(extension or normal) is a good choice.
0
 
LVL 4

Accepted Solution

by:
mblat earned 200 total points
ID: 7173479
It doesn't matter what kind of DLL to use.  But if I read your question correctly your probably intrested in so called "resource-only" DLLs, that used to translate application to separate languages.

If that the case then generally accepted practice is to use straight Win32 DLL.

So what you need to do is following:

HINSTANCE hLanguageDll = LoadLibrary("ENGLISH.DLL");

Now switch resource handle

HINSTANCE hOldResource = AfxGetResourceHandle( );
AfxSetResourceHandle(hLanguageDll );

... load resource here

// switch back to old resource handle
AfxSetResourceHandle(hOldResource );

Of cause switching back to old resource handle is needed only if you have you resources in more than one DLL or in DLL and .exe.

Good place to load library would be in InitInstance()

If you have resource in extansiaon Dll and using it from withing extension dll then you can to do solething like this:

...somewhere in code ( this is created by wizard )
static AFX_EXTENSION_MODULE MyExtDLL = { NULL, NULL };

.......
void ThisIsFunctionInExtensionDLL()
{
HINSTANCE hOldResource = AfxGetResourceHandle( );
AfxSetResourceHandle(MyExtDLL.hModule);

... load resource here

// switch back to old resource handle
AfxSetResourceHandle(hOldResource );
}



Hope it helps...
0
ScreenConnect 6.0 Free Trial

Want empowering updates? You're in the right place! Discover new features in ScreenConnect 6.0, based on partner feedback, to keep you business operating smoothly and optimally (the way it should be). Explore all of the extras and enhancements for yourself!

 

Author Comment

by:Khawar091697
ID: 7173480
But pls. also write how can i use that hYourDialog furthr to display that dialog. Let's suppose the exe client is a simple mfc doc/view app. and i want to show a dialog on File/New
0
 

Author Comment

by:Khawar091697
ID: 7173490
Mr. BeyondWu!
what is the value of YourDialogProc... what is this??
Thanks
0
 
LVL 4

Expert Comment

by:mblat
ID: 7174866
IF you are extension DLL then you are supporting MFC.  Why not derive class for you dialog, then you can do


HINSTANCE hOldResource = AfxGetResourceHandle( );
AfxSetResourceHandle(MyExtDLL.hModule);

CMyDialog d;

d.DoModal();

// switch back to old resource handle
AfxSetResourceHandle(hOldResource );
0
 
LVL 9

Expert Comment

by:BeyondWu
ID: 7175983
YourDlgProc is your dialog box procedure;
Do you ever program for windows with SDK?!
0

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
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.
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

809 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