DLL callback pointer

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

#define   DLLPATH "../../testdll/release/testdll.dll"

//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 .

:

 //use DLL funcs without lib or def files

                              //this works
  GetInst = (INSTPROC)GetProcAddress(Loadme,"getinst");
                              //this works
  GetID   = (VOIDPROC)GetProcAddress(Loadme,"getid");
                              //this doesn't work, rets 0
  DlgProc = (DLGPROC) GetProcAddress(Loadme,"dllProc");

  //test for result
  dllid  =(GetID)();
  dllinst=(GetInst)();

  //compare hinst            OK
  wsprintf(buf,"dllinst=%x  Loadme=%x",dllinst, Loadme);
  MessageBox(hwnd,buf,"",MB_OK);

  //check resOurce ID        OK
  wsprintf(buf,"GetID returned: %d",dllid);
  MessageBox(hwnd,buf,"",MB_OK);

  //check dllProc addr       NOGO, ret=0
  wsprintf(buf,"dllProc=%x",DlgProc);
  MessageBox(hwnd,buf,"",MB_OK);

        //    DLL instance,        resource ID,     parent,  dlgproc    
        DialogBox(Loadme  ,  MAKEINTRESOURCE(dllid),  hwnd,  DlgProc);

  //dialog loads and shows, can't get dlgproc addr 

        FreeLibrary(Loadme);
        ///////////////// END DLL TEST STUFF ///////////////

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;
}

, .

- , , .

.

+3
1

dllProc extern "C", , , "dllProc", ( "dllProc @blahmoocow" ++-.: -)).

dllProc:

extern "C"
{
    __declspec(dllexport) LRESULT CALLBACK dllProc(
           HWND hwnd, UINT Message, WPARAM wParam, PARAM lParam);
}

__declspec(dllexport) dllProc.

+2

Source: https://habr.com/ru/post/1778461/


All Articles