Click here to Skip to main content
15,897,273 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
QuestionLoad Dialog From a Resource DLL Pin
goldenrose911-Jan-11 3:31
goldenrose911-Jan-11 3:31 
QuestionRe: Load Dialog From a Resource DLL Pin
Cool_Dev11-Jan-11 3:49
Cool_Dev11-Jan-11 3:49 
AnswerRe: Load Dialog From a Resource DLL Pin
goldenrose911-Jan-11 4:46
goldenrose911-Jan-11 4:46 
GeneralRe: Load Dialog From a Resource DLL Pin
Cool_Dev11-Jan-11 16:23
Cool_Dev11-Jan-11 16:23 
GeneralRe: Load Dialog From a Resource DLL Pin
goldenrose911-Jan-11 16:43
goldenrose911-Jan-11 16:43 
AnswerRe: Load Dialog From a Resource DLL Pin
User 742933811-Jan-11 3:54
professionalUser 742933811-Jan-11 3:54 
GeneralRe: Load Dialog From a Resource DLL Pin
goldenrose911-Jan-11 4:53
goldenrose911-Jan-11 4:53 
GeneralRe: Load Dialog From a Resource DLL Pin
Andrew Brock11-Jan-11 4:46
Andrew Brock11-Jan-11 4:46 
If you are using MFC you can create an instance of the dialog class from the DLL. Be sure to use MFC with dynamic linking in both the exe and dll.
The way I did this in my project was:
In the DLL have
class MyDialog : public CDialog {
	//program this class as if it was part of the exe
}


Then an exported function to create and destroy the instance.
Because in C++ the return type and parameters make up the function name, we should use C for exporting functions, however we cannot create classes in C.
Any memory allocated from within a DLL should be deleted from within the DLL too, so we need a create and destroy function
The following will create an instance of the class and return it through a C function and delete it when you are finished with it.
//This function name is ?InternalGetDialog@@YAPEAXXZ if it was exported. Which is why we don't.
void *InternalGetDialog() {
	return new MyDialog();
}

//This function name is ?InternalDeleteDialog@@YAXPEAVCDialog@@@Z if it was exported. Which is why we don't.
//This is a generic function that will destroy any dialog created from this dll
void InternalDeleteDialog(void *pDlg) {
	CDialog *pDialog = (CDialog *)pDialog; //cast so that we call the destructor
	delete pDialog;
}

extern "C" {
	//This function name is GetDialog when importing
	__declspec(dllexport) void *GetDialog() {
		return InternalGetDialog();
	}
	//This function name is DeleteDialog when importing
	__declspec(dllexport) void DeleteDialog(void *pDialog) {
		InternalDeleteDialog(pDialog);
	}
}


Then in the exe that displays the dialog
typedef CDialog *(*GetDialogFunc)();
typedef CDialog *(*DeleteDialogFunc)();

void DisplayDynamicDialog() {
	HMODULE hModule = LoadLibrary("Resources.dll");
	if (hModule != NULL) {
		GetDialogFunc pGetDialogFunc = (GetDialogFunc)GetProcAddress(hModule, "GetDialog");
		DeleteDialogFunc pDeleteDialogFunc = (DeleteDialogFunc)GetProcAddress(hModule, "DeleteDialog");
		CDialog *pDialog = pGetDialogFunc();
		INT_PTR nRes = pDialog->DoModal();
		//check nRes, process what is on the dialog, ...
		pDeleteDialogFunc(pDialog);
		FreeLibrary(hModule);
	}
}

GeneralRe: Load Dialog From a Resource DLL Pin
goldenrose911-Jan-11 4:49
goldenrose911-Jan-11 4:49 
AnswerRe: Load Dialog From a Resource DLL Pin
Andrew Brock11-Jan-11 5:09
Andrew Brock11-Jan-11 5:09 
GeneralRe: Load Dialog From a Resource DLL Pin
goldenrose911-Jan-11 19:53
goldenrose911-Jan-11 19:53 
AnswerRe: Load Dialog From a Resource DLL Pin
Abhi Lahare11-Jan-11 5:19
Abhi Lahare11-Jan-11 5:19 
AnswerRe: Load Dialog From a Resource DLL Pin
Richard MacCutchan11-Jan-11 5:58
mveRichard MacCutchan11-Jan-11 5:58 
GeneralRe: Load Dialog From a Resource DLL Pin
goldenrose911-Jan-11 16:40
goldenrose911-Jan-11 16:40 
GeneralRe: Load Dialog From a Resource DLL Pin
Richard MacCutchan11-Jan-11 21:13
mveRichard MacCutchan11-Jan-11 21:13 
GeneralRe: Load Dialog From a Resource DLL Pin
goldenrose912-Jan-11 4:27
goldenrose912-Jan-11 4:27 
QuestionActivex control in linux Pin
Sakhalean11-Jan-11 2:42
Sakhalean11-Jan-11 2:42 
AnswerRe: Activex control in linux Pin
CPallini11-Jan-11 2:49
mveCPallini11-Jan-11 2:49 
GeneralRe: Activex control in linux Pin
Sakhalean11-Jan-11 3:01
Sakhalean11-Jan-11 3:01 
AnswerRe: Activex control in linux Pin
Cool_Dev11-Jan-11 2:50
Cool_Dev11-Jan-11 2:50 
QuestionListing Unused Variables Pin
softwaremonkey11-Jan-11 2:31
softwaremonkey11-Jan-11 2:31 
AnswerRe: Listing Unused Variables Pin
Maximilien11-Jan-11 2:41
Maximilien11-Jan-11 2:41 
GeneralRe: Listing Unused Variables Pin
Luc Pattyn11-Jan-11 3:12
sitebuilderLuc Pattyn11-Jan-11 3:12 
GeneralRe: Listing Unused Variables Pin
Maximilien11-Jan-11 6:34
Maximilien11-Jan-11 6:34 
GeneralRe: Listing Unused Variables Pin
Luc Pattyn11-Jan-11 6:46
sitebuilderLuc Pattyn11-Jan-11 6:46 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.