Solved

want resource templates export from dll

Posted on 2011-02-17
2
601 Views
Last Modified: 2013-11-20
I have an MFC dll where I comfortably use the AFX_CLASS_EXPORT to export complete classes.
on of them is a CDialog derived class which has some resource template.

The point is, when I call dlg.DoModal() in my app, it returns -1 because it searches the Resource in the app , not the dll. How do I call doModal on the exported instance, and load the resource from the dll ?

class AFX_CLASS_EXPORT CMyDllDlg : public CDialog
{...
}

app.exe:

dlg CMyDllDlg; // OK
dlg.DoModal() // resource problem!

Open in new window

0
Comment
Question by:stev75
2 Comments
 
LVL 5

Accepted Solution

by:
JohnCz earned 500 total points
Comment Utility
From your descrition of the problem it looks like you are using regular MFC dll.
It requires switching resource handle to tell the app what resource to use.
Your code should look like this:

	HMODULE hLib = LoadLibrary(_T("YourResDllName.dll"));

	ASSERT(hLib != NULL);

	AfxSetResourceHandle(hLib);	// switch to dll resource


	CDllDlg dlg;

	int iret = dlg.DoModal();

	AfxSetResourceHandle(AfxGetInstanceHandle());   // switch back to app resource

Open in new window


Another thing is a macro that you are using to export class. In general it is designed to use in MFC extension dll. It may create a confusion if you are using MFC extension DLL. Besides, in the main project, both AFX_CLASS_EXPORT and AFX_CLASS_IMPORT are defined.
Consider using different, safer approach:

#ifdef DLG_FROM_DLL
#define DLG_FROM_DLL_EXPORT __declspec(dllexport)
#else
#define DLG_FROM_DLL_EXPORT __declspec(dllimport)
#endif
class DLG_FROM_DLL_EXPORT CMyDllDlg : public CDialog
{...
};

Open in new window


In dll project properties, for a C++ in Preprocessor Definitions add DLG_FROM_DLL.
This way when file is included in a dll project, class is exported; in an app project (since DLG_FROM_DLL is not defined, class is impoerted.
0
 

Author Closing Comment

by:stev75
Comment Utility
i had to switch to the "extension dll". Then with your additions, it works well.
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
VS2015 compilation and missing DLLs 9 96
while loop over for loop 7 79
maven archtype selection in eclipse 1 51
fizzArray  challenge 1 47
For most people, the WrapPanel seems like a magic when they switch from WinForms to WPF. Most of us will think that the code that is used to write a control like that would be difficult. However, most of the work is done by the WPF engine, and the W…
A theme is a collection of property settings that allow you to define the look of pages and controls, and then apply the look consistently across pages in an application. Themes can be made up of a set of elements: skins, style sheets, images, and o…
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 is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…

744 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

17 Experts available now in Live!

Get 1:1 Help Now