Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7780473
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T18:54:34+00:00 2026-06-01T18:54:34+00:00

I want to call MessageBox() function in such way: 1). load needed library 2).

  • 0

I want to call MessageBox() function in such way:

1). load needed library
2). get the function address
3). call it

So, for such aim as I understand, I should define new type with all types of arguments in MessageBox function.

It returnes INT and accepts: HWND, LPCSTR, LPCSTR, UNIT.

So I registred new type:

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

I have problems with calling such function. Does such way work for all functions or only for exported?
How can I call MessageBox exactly in such 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;
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T18:54:36+00:00Added an answer on June 1, 2026 at 6:54 pm

    Why are you declaring everything as a pointer?

    LoadLibrary returns an HMODULE, not an HINSTANCE__ * (it will work with the latter but it’s always better to adhere to the documentation).

    Similarly, msgbox is typedef‘d to a function pointer type, so me is a msgbox, not a msgbox *.

    The reason why GetProcAddress fails is because user32.dll exports 2 functions, MessageBoxA and MessageBoxW. When you simply call MessageBox in your code, macros defined in Windows.h replace it with one of the 2 actual function names depending on whether you’re compiling for UNICODE or not. But when you’re trying to directly access the exported function as you are doing, you need to explicitly specify which one you’re trying to get a pointer to.

    #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 );
      }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

When I want to call some Windows function, like MessageBox I can import it
I want to call this WS http://www.webservicex.net/country.asmx?op=GetCountries What is the best possible way to
I want to call a controller function from a view. Is that possible in
I want to call the Sleep function on ASM. So I wrote the following:
I want to call a JavaScript function through PHP and store the returned value
Is there a way to call MessageBox.Show that appears in the taskbar? It would
Based on my research, the only way to get a MessageBox Form to Center
I want to call a webservice from jQuery. How can I do that?
I want to call a google service using javascript with a keyword and a
I want to call a Subversion API from a Visual Studio 2003 C++ project.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.