Solved

Loading Dialog resources in an MFC exe project?

Posted on 2002-07-23
7
757 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
Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

 

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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
repeateFront java challenge 31 94
Doc'in system (example?) BA 7 115
either24  challenge 19 101
Trying to run powershell  in a batch file. How do I do this? 8 105
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
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 video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

791 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