Load Dialog From a Resource DLL
-
I need a sample of how to load dialog resource from a dll I found a sample here but it is not working. http://www.codeproject.com/Messages/1212280/Re-how-to-load-dialog-resource-from-a-dll.aspx
// Load the resource dll
HMODULE hModule = LoadLibrary("C:\\another_resource.dll");if(hModule != NULL)
{
// Loading your dialog
HWND hDialog = CreateDialog(hModule, MAKEINTRESOURCE(ID_DIALOG), /* Handle to parent window */, /* Pointer to dialog procedure function */);// Loading your bitmap
HBITMAP hBitmap = LoadBitmap(hModule, MAKEINTRESOURCE(IDB_BITMAP);FreeLibrary(hModule);
}thanx in advance please help
Some Day I Will Prove MySelf :: GOLD
-
I need a sample of how to load dialog resource from a dll I found a sample here but it is not working. http://www.codeproject.com/Messages/1212280/Re-how-to-load-dialog-resource-from-a-dll.aspx
// Load the resource dll
HMODULE hModule = LoadLibrary("C:\\another_resource.dll");if(hModule != NULL)
{
// Loading your dialog
HWND hDialog = CreateDialog(hModule, MAKEINTRESOURCE(ID_DIALOG), /* Handle to parent window */, /* Pointer to dialog procedure function */);// Loading your bitmap
HBITMAP hBitmap = LoadBitmap(hModule, MAKEINTRESOURCE(IDB_BITMAP);FreeLibrary(hModule);
}thanx in advance please help
Some Day I Will Prove MySelf :: GOLD
-
I need a sample of how to load dialog resource from a dll I found a sample here but it is not working. http://www.codeproject.com/Messages/1212280/Re-how-to-load-dialog-resource-from-a-dll.aspx
// Load the resource dll
HMODULE hModule = LoadLibrary("C:\\another_resource.dll");if(hModule != NULL)
{
// Loading your dialog
HWND hDialog = CreateDialog(hModule, MAKEINTRESOURCE(ID_DIALOG), /* Handle to parent window */, /* Pointer to dialog procedure function */);// Loading your bitmap
HBITMAP hBitmap = LoadBitmap(hModule, MAKEINTRESOURCE(IDB_BITMAP);FreeLibrary(hModule);
}thanx in advance please help
Some Day I Will Prove MySelf :: GOLD
-
create dialog.. Is required, I have the correct dialog id and i m able to load the dll using loadlibrary(). After this i m confused what to do next, so i need a small example that demonstrate how to show the dialog from resource dll. Thanx in advance.
Some Day I Will Prove MySelf :: GOLD
-
I need a sample of how to load dialog resource from a dll I found a sample here but it is not working. http://www.codeproject.com/Messages/1212280/Re-how-to-load-dialog-resource-from-a-dll.aspx
// Load the resource dll
HMODULE hModule = LoadLibrary("C:\\another_resource.dll");if(hModule != NULL)
{
// Loading your dialog
HWND hDialog = CreateDialog(hModule, MAKEINTRESOURCE(ID_DIALOG), /* Handle to parent window */, /* Pointer to dialog procedure function */);// Loading your bitmap
HBITMAP hBitmap = LoadBitmap(hModule, MAKEINTRESOURCE(IDB_BITMAP);FreeLibrary(hModule);
}thanx in advance please help
Some Day I Will Prove MySelf :: GOLD
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);
}
} -
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);
}
}thanx 4 ur reply with sample but i need the sample in win32 way, my program don't use MFC.
Some Day I Will Prove MySelf :: GOLD
-
Is the resource ID
ID_DIALOG
in the calling program equal to what was used in the DLL? If you're not sure and you don't have the DLL's code to look it up, you could analyse the DLL with the resource hacker[^].i have the correct id, i need a small code to show the dialog from reource dll in win32 way
Some Day I Will Prove MySelf :: GOLD
-
I need a sample of how to load dialog resource from a dll I found a sample here but it is not working. http://www.codeproject.com/Messages/1212280/Re-how-to-load-dialog-resource-from-a-dll.aspx
// Load the resource dll
HMODULE hModule = LoadLibrary("C:\\another_resource.dll");if(hModule != NULL)
{
// Loading your dialog
HWND hDialog = CreateDialog(hModule, MAKEINTRESOURCE(ID_DIALOG), /* Handle to parent window */, /* Pointer to dialog procedure function */);// Loading your bitmap
HBITMAP hBitmap = LoadBitmap(hModule, MAKEINTRESOURCE(IDB_BITMAP);FreeLibrary(hModule);
}thanx in advance please help
Some Day I Will Prove MySelf :: GOLD
Firstly you need a message handler, essentialy the same as your main message handler, usually WndProc
BOOL CALLBACK DlgProc(HWND hDlg, UINT nMessage, WPARAM wParam, LPARAM lParam) {
switch (nMessage) {
case WM_INITDIALOG:
//This is where you do all your initialisation. This is the first place after all the controls have been created, so you can use GetDlgItem()
return TRUE;case WM\_COMMAND: //This is the same as it is in the WndProc, handle button clicks, etc... switch (LOWORD(wParam)) { case IDOK: //This is usually the OK or Done button return TRUE; case IDCANCEL: //This is usually the Close or Cancel button DestroyWindow(hDlg); //close the dialog return TRUE; } break; } } return FALSE;
}
Then you just need to use that as the "procedure function"
void DisplayDynamicDialog(HWND hParent) {
HMODULE hModule = LoadLibrary("Resources.dll");
if(hModule != NULL) {
hDialog = CreateDialog(hModule, MAKEINTRESOURCE(ID_DIALOG), hParent, (DLGPROC)DlgProc);
ShowWindow(hDialog, SW_SHOW);
FreeLibrary(hModule); //This might need to be called later, after the dialog has been closed since it is modeless
}
}Finally, just to reiterate what Thaddeus Jones said, the ID you supply needs to be the ID defined in the DLL, not the ID defined in the exe, hence the resource.h that you include needs to be from the dll. To avoid confusion, I recommend using quoted string names instead.
-
I need a sample of how to load dialog resource from a dll I found a sample here but it is not working. http://www.codeproject.com/Messages/1212280/Re-how-to-load-dialog-resource-from-a-dll.aspx
// Load the resource dll
HMODULE hModule = LoadLibrary("C:\\another_resource.dll");if(hModule != NULL)
{
// Loading your dialog
HWND hDialog = CreateDialog(hModule, MAKEINTRESOURCE(ID_DIALOG), /* Handle to parent window */, /* Pointer to dialog procedure function */);// Loading your bitmap
HBITMAP hBitmap = LoadBitmap(hModule, MAKEINTRESOURCE(IDB_BITMAP);FreeLibrary(hModule);
}thanx in advance please help
Some Day I Will Prove MySelf :: GOLD
you can also use combination of LoadResource[^] and FindResouce[^]
-
I need a sample of how to load dialog resource from a dll I found a sample here but it is not working. http://www.codeproject.com/Messages/1212280/Re-how-to-load-dialog-resource-from-a-dll.aspx
// Load the resource dll
HMODULE hModule = LoadLibrary("C:\\another_resource.dll");if(hModule != NULL)
{
// Loading your dialog
HWND hDialog = CreateDialog(hModule, MAKEINTRESOURCE(ID_DIALOG), /* Handle to parent window */, /* Pointer to dialog procedure function */);// Loading your bitmap
HBITMAP hBitmap = LoadBitmap(hModule, MAKEINTRESOURCE(IDB_BITMAP);FreeLibrary(hModule);
}thanx in advance please help
Some Day I Will Prove MySelf :: GOLD
-
create dialog.. Is required, I have the correct dialog id and i m able to load the dll using loadlibrary(). After this i m confused what to do next, so i need a small example that demonstrate how to show the dialog from resource dll. Thanx in advance.
Some Day I Will Prove MySelf :: GOLD
-
i know it is incomplete, therefore i m in need of a sample in win32 way.
Some Day I Will Prove MySelf :: GOLD
-
see from msdn documentation http://msdn.microsoft.com/en-us/library/ms644996%28v=vs.85%29.aspx#modeless_box[^]
thanx, but i need help in displaying a dialog from a resouce dll.
Some Day I Will Prove MySelf :: GOLD
-
Firstly you need a message handler, essentialy the same as your main message handler, usually WndProc
BOOL CALLBACK DlgProc(HWND hDlg, UINT nMessage, WPARAM wParam, LPARAM lParam) {
switch (nMessage) {
case WM_INITDIALOG:
//This is where you do all your initialisation. This is the first place after all the controls have been created, so you can use GetDlgItem()
return TRUE;case WM\_COMMAND: //This is the same as it is in the WndProc, handle button clicks, etc... switch (LOWORD(wParam)) { case IDOK: //This is usually the OK or Done button return TRUE; case IDCANCEL: //This is usually the Close or Cancel button DestroyWindow(hDlg); //close the dialog return TRUE; } break; } } return FALSE;
}
Then you just need to use that as the "procedure function"
void DisplayDynamicDialog(HWND hParent) {
HMODULE hModule = LoadLibrary("Resources.dll");
if(hModule != NULL) {
hDialog = CreateDialog(hModule, MAKEINTRESOURCE(ID_DIALOG), hParent, (DLGPROC)DlgProc);
ShowWindow(hDialog, SW_SHOW);
FreeLibrary(hModule); //This might need to be called later, after the dialog has been closed since it is modeless
}
}Finally, just to reiterate what Thaddeus Jones said, the ID you supply needs to be the ID defined in the DLL, not the ID defined in the exe, hence the resource.h that you include needs to be from the dll. To avoid confusion, I recommend using quoted string names instead.
:thumbsup: thanks a lot, worked like a charm, once again thanx.
Some Day I Will Prove MySelf :: GOLD
-
i know it is incomplete, therefore i m in need of a sample in win32 way.
Some Day I Will Prove MySelf :: GOLD
-
sir i had received the answer, thanx for giving ur valuable time sir.
Some Day I Will Prove MySelf :: GOLD