c++64-bitgetprocaddress

C++ GetProcAddress 64bit returns 32bit address


I have been searching for a while and didnt find an appropriate answer for the following problem:

I'm injecting a dll into a target process while inside the dll, I try to call an exported function which address I want to receive my calling GetProcAddress as followed:

FARPROC funcAddr =
GetProcAddress(GetModuleHandle("target.dll"), "exportedFunc")

The call succeeds, I retrieve the address and the GetLastError() is 0, obviously.

But it is just the 16-byte hexadecimal representation of the address (like "0xAB4285B9"), but I need it for 32-byte hexadecimal representation since I am missing the previous 8 bytes (7FF8 for example, complete address would then be "0x7FF8AB4285B9")

Is it just a presentation/format Problem or do I need to call another function to get what I want?

I display the information like:

WCHAR buffer[256];
swprintf_s(buffer, 32, L"%X", funcAddr);
MessageBox(NULL, buffer, L"Address", MB_OK);

I appreciate any help.

Sorry for non-code formattings, I'm using my phone's web browser here.

Greetz


Solution

  • Alright since I read a little bit deeper into the topic I understood and changed my solution in order to make it working properly (special thanks to @cheers and hth):

    WCHAR buffer[256];
    swprintf_s(buffer, 32, L"%p", funcAddr);
    MessageBox(NULL, buffer, L"Address", MB_OK);
    

    By simply changing format of "%X" to "%p" which represents pointer address representation. Simple as that.