Solved

Loading Dialog resources in an MFC exe project?

Posted on 2002-07-23
7
793 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
[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 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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

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: 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.
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…

691 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