Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

want resource templates export from dll

Posted on 2011-02-17
2
Medium Priority
?
613 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
[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
2 Comments
 
LVL 5

Accepted Solution

by:
Janusz Czopowik earned 2000 total points
ID: 34916036
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
ID: 34940906
i had to switch to the "extension dll". Then with your additions, it works well.
0

Featured Post

Get your Conversational Ransomware Defense e‑book

This e-book gives you an insight into the ransomware threat and reviews the fundamentals of top-notch ransomware preparedness and recovery. To help you protect yourself and your organization. The initial infection may be inevitable, so the best protection is to be fully prepared.

Question has a verified solution.

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

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 …
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…

618 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