Click here to Skip to main content
15,910,773 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I wanted to use the resource such as the form in the Win32 DLL and pop up the dialog in the DLL exported function. That's means when I call the exported function, the dialog pops up, thanks!! How can I do this?


#include "resource.h"
#include<windows.h>
HINSTANCE hinst=NULL;     
HWND hwndDLG=NULL;   
BOOL   CALLBACK   DlgProc(HWND hDlg,UINT message,WPARAM wParam,LPARAM lParam);     

extern "C" __declspec(dllexport) void ShowDlg()      //
{   
    hinst=LoadLibrary("Modal_Dialog.dll");  
 hwndDLG=CreateDialog(hinst,MAKEINTRESOURCE(IDD_DIALOG1),NULL,(DLGPROC)DlgProc);         
 ShowWindow(hwndDLG,SW_SHOW);  
 UpdateWindow (hwndDLG) ; 
// hinst=LoadLibrary("Modal_Dialog.dll");      
// DialogBox(hinst,MAKEINTRESOURCE(IDD_DIALOG1),NULL,DlgProc);  // FreeLibrary(hinst);
 
}     
BOOL CALLBACK DlgProc(HWND hDlg,UINT message,WPARAM wParam,LPARAM lParam)     
{         
 switch(message)       
 {       
 case   WM_INITDIALOG:       
  return   TRUE;       
 case   WM_CLOSE:     
  DestroyWindow(hDlg);       
  hwndDLG   =   NULL;       
  return   TRUE;       
 }     
 return   FALSE;     
}
Posted
Updated 27-Dec-09 21:07pm
v5

There are mainly two ways to do this:

1) Let the dialog to leave into the DLL, and implement in the DLL an exported function that creates and run the dialog.
The exported function will be in the DLL itself and in the corresponding "import library" you have to link to your program (that's no more different than exporting a function from a DLL)

2) Let the resource to be defined in the DLL, load the library from your program (the DLL itself, via LoadLibrary), Than call a dialog execution API (like DialogBox or CreateDialog) passing the library handle.
 
Share this answer
 
v2
Thanks,emilio_grv , «_Superman_».
what about my codes??would you give some advise to my codes ,thanks.
 
Share this answer
 
v3
Please rephrase and explain your question a little more clearly.
Assuming you want to show a dialog whose template resides as a resource in another DLL, calls the following APIs in order.
LoadLibrary
FindResource
LoadResource
LockResource
DialogBoxIndirect
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900