[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Loading Dialog resources in an MFC exe project?

Posted on 2002-07-23
7
Medium Priority
?
830 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 600 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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 

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

Moving data to the cloud? Find out if you’re ready

Before moving to the cloud, it is important to carefully define your db needs, plan for the migration & understand prod. environment. This wp explains how to define what you need from a cloud provider, plan for the migration & what putting a cloud solution into practice entails.

Question has a verified solution.

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

Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
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.
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
Suggested Courses

656 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