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
Solved

want resource templates export from dll

Posted on 2011-02-17
2
606 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
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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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

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

839 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