c++typedefhwndstdcalllpcstr

Learning reversing via C++, but what does this line do?


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

As I said, im trying to learn how to reverse engineer programs using C++ / Assembly, so I'm going through some open source projects I found on the internet. But can anyone explain what this line does? Im not advanced in C++, which is why I'm going through sources.


Solution

  • Your code is C language. So it also compiles fine in C++.

    Let 's go step by step.

    1. Here is a function declaration or prototype or signature.
      It returns an int, accepts 4 parameters :
    int __stdcall MessageBoxA(HWND, LPCSTR, LPCSTR, UINT); 
    
    1. Here ptr is a pointer variable to a function :
    int(__stdcall *ptr)(HWND, LPCSTR, LPCSTR, UINT); 
    ptr = NULL;
    / assign a correct adress
    ptr = MessageBoxA;
    // call the function with parameters using the pointer
    (*ptr)(hWnd, NULL, NULL, 0); 
    
    1. Here __MessageBoxA is a type that helps to define a variable that is a pointer to a function:
    typedef int(__stdcall *__MessageBoxA)(HWND, LPCSTR, LPCSTR, UINT); 
    

    So a pointer to a function variable can be declared.

    __MessageBoxA ptr1 = NULL;
    

    __stdcall is the way the function is called by the compiler ( Are parameters passed from left to right or reverse ? Is return value passed through stack memory or CPU register ?) - details most people don't care as long as caller and called agree

    Regards