How to call MessageBox with GetProcAddress function?

I want to call the MessageBox () function this way:

1). Download the required library
2). get the address of the function
3). call him

So, for this purpose, as I understand it, I have to define a new type with all types of arguments in the MessageBox function.

It returns an INT and accepts: HWND, LPCSTR, LPCSTR, UNIT.

So, I registered a new type:

typedef int(__stdcall *msgbox)(HWND, LPCSTR, LPCSTR, UINT);

I have problems calling such a function. Is this method used for all functions or only for export?
How can I call a MessageBox exactly this way?

Full code:

#include <iostream>
#include <windows.h>

using namespace std;

typedef int(__stdcall *msgbox)(HWND, LPCSTR, LPCSTR, UINT);

int main(void)
{
    HINSTANCE__ *hModule = LoadLibrary(L"\\Windows\\System32\\User32.dll");
    msgbox *me = 0;

    if(hModule != 0)
    {
        me = (msgbox*)GetProcAddress(hModule, "MessageBox");
    }

    return 0;
}

Thanks,
Best regards!

+3
source share
1 answer

?

LoadLibrary HMODULE, HINSTANCE__ * ( , ).

, msgbox typedef 'd , me msgbox, msgbox *.

GetProcAddress , user32.dll 2 , MessageBoxA MessageBoxW. MessageBox , , Windows.h, , UNICODE . , , , .

#include <iostream>
#include <windows.h>

typedef int(__stdcall *msgbox)(HWND, LPCSTR, LPCSTR, UINT);

int main(void)
{
  HMODULE hModule = ::LoadLibrary(L"User32.dll");
  msgbox me = NULL;

  if( hModule != NULL ) {
    me = reinterpret_cast<msgbox>( ::GetProcAddress(hModule, "MessageBoxA") );
  }

  if( me != NULL ) {
    (*me)( NULL, "I'm a MessageBox", "Hello", MB_OK );
  }

  if( hModule != NULL ) {
    ::FreeLibrary( hModule );
  }
}
+3

All Articles