I call a dialog box with resources and a dlg procedure in a DLL. I do not use a DEF file or a LIB file. Function names are known, args are known, I use GetProcAddress to get a pointer to the functions that interest me.
“Why” I do it this way does not make any difference, it is an experiment in “learning”.
This works in _cdecl functions, but on CALLBACK (_stdcall) I cannot get a pointer to the actual dialog procedure (it returns 0).
This is how I make my pointers:
//////////////////// DLL TEST STUFF ////////////////////////////
//typedef some function pointers
typedef HINSTANCE (__cdecl *INSTPROC )(void);
typedef int (__cdecl *VOIDPROC )(void);
typedef LRESULT (__stdcall *DLGROC )(HWND, UINT, WPARAM, LPARAM );
///////////////////////////////////////////////////////////////
As I said, any function that is NOT a callback returns a valid result, in addition, a dialog box appears, as expected, no problems with the HINSTANCE DLL.
dlgproc .
:
GetInst = (INSTPROC)GetProcAddress(Loadme,"getinst");
GetID = (VOIDPROC)GetProcAddress(Loadme,"getid");
DlgProc = (DLGPROC) GetProcAddress(Loadme,"dllProc");
dllid =(GetID)();
dllinst=(GetInst)();
wsprintf(buf,"dllinst=%x Loadme=%x",dllinst, Loadme);
MessageBox(hwnd,buf,"",MB_OK);
wsprintf(buf,"GetID returned: %d",dllid);
MessageBox(hwnd,buf,"",MB_OK);
wsprintf(buf,"dllProc=%x",DlgProc);
MessageBox(hwnd,buf,"",MB_OK);
DialogBox(Loadme , MAKEINTRESOURCE(dllid), hwnd, DlgProc);
FreeLibrary(Loadme);
DLL :
__declspec(dllexport) LRESULT CALLBACK dllProc(
HWND hwnd,
UINT Message,
WPARAM wParam,
LPARAM lParam
)
{
hpwnd=hwnd;
switch (Message){
case WM_INITDIALOG:
MessageBox(hwnd,"At DlgProc...","",MB_OK);
return TRUE;
case WM_COMMAND:
switch(LOWORD(wParam)){
case IDEND:
case IDCANEND:
EndDialog(hwnd,0);
return TRUE;
}
return TRUE;
}
return FALSE;
}
, .
- , , .
.