Search code examples
dllexegetprocaddress

getprocaddress acting different from a dll and an exe


I'm trying get the address of GetProcAddress with GetProcAddress (yes. calling it on itself). When I'm doing it from an empty exe project I get a valid address (between the allocated address of kernel32).

When I'm calling it from a dll, I'm getting invalid address (not in the range of the allocated kernel32)

What is the difference? I'm running on windows 7 with 64 bit.

The project are compiled as 32 bit. Here is the code that I'm running:

typedef FARPROC (WINAPI * GetProcAddressType)(HMODULE , LPCSTR );

HMODULE kernel32Hmodule = LoadLibraryW(L"c:\windows\system32\kernel32.dll");

GetProcAddressType abc = (GetProcAddressType)GetProcAddress(kernel32Hmodule, "GetProcAddress");

I also tried to get the address like this: void* a = GetProcAddress; but it returns the same invalid address when running from a dll...

Please help.


Solution

  • ok i found the problem. when i loaded the dll with rundll32 it acted wierd... when i build a loader by myself (loadlibrary, than getprocaddress) it worked fine. rundll32 is the one caused the problems