Search code examples
apiloadlibrarykernel32

GetProcAdress returns always zero


I encountered a really mysterious problem. Using the function GetProcAddress, I always get zero.

Debug.Print(GetProcAddress(LoadLibraryExA("kernel32"), "CreateProcess"))

This line returns always zero no matter if I use "CreateProcess", "LoadLibrary" or something else. Why is this so?

Declaration of the functions:

Declare Function LoadLibraryExA Lib "kernel32" (ByVal name As String) As IntPtr
    Declare Ansi Function GetProcAddress Lib "kernel32" (ByVal handle As IntPtr, ByVal name As String) As IntPtr

Solution

  • The name of the "CreateProcess" API is actually either CreateProcessW or CreateProcessA depending on if you're using the UNICODE API or not.