Solved

Loading Dialog resources in an MFC exe project?

Posted on 2002-07-23
7
713 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
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 

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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Suggested Solutions

In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
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 demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

757 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

23 Experts available now in Live!

Get 1:1 Help Now