(4.40b2 x86) GetProcAddress_() returns wrong value

Just starting out? Need help? Post your questions and find answers here.
breeze4me
Enthusiast
Enthusiast
Posts: 633
Joined: Thu Mar 09, 2006 9:24 am
Location: S. Kor

(4.40b2 x86) GetProcAddress_() returns wrong value

Post by breeze4me »

Code: Select all

hMod = GetModuleHandle_("Kernel32.dll")
Debug hMod

*p = GetProcAddress_(hMod, "GetCurrentProcessId")
Debug *p  ;<---------- 0

If OpenLibrary(0, "Kernel32.dll")
  Debug GetFunction(0, "GetCurrentProcessId")
EndIf
unicode mode.
;2088763392
;0
;2088802592
ascii mode.
;2088763392
;2088802592
;2088802592
Thorium
Addict
Addict
Posts: 1305
Joined: Sat Aug 15, 2009 6:59 pm

Re: (4.40b2 x86) GetProcAddress_() returns wrong value

Post by Thorium »

Confirmed for x86 and x64

Maybe it's because GetProcAddress allways wants a ASCII String.
Fred
Administrator
Administrator
Posts: 18264
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Re: (4.40b2 x86) GetProcAddress_() returns wrong value

Post by Fred »

Yes, it is. You will have to handle this yourself, as PB string are UTF-16 in Unicode mode (best is to use an import with p-ascii like below):

Code: Select all

Import "Kernel32.lib"
  GetProcAddressAscii_(Module, FunctionName.p-ascii) As "_GetProcAddress@8" ; Should be "GetProcAddress" for x64
EndImport

hMod = GetModuleHandle_("Kernel32.dll")
Debug hMod

*p = GetProcAddressAscii_(hMod, "GetCurrentProcessId")
Debug *p
Poplar
User
User
Posts: 16
Joined: Sun Apr 30, 2017 12:27 pm

Re: (4.40b2 x86) GetProcAddress_() returns wrong value

Post by Poplar »

hMod = GetModuleHandle_("Kernel32.dll")
Debug hMod

*p = GetProcAddress_(hMod, UTF8("GetCurrentProcessId"))
Debug *p ;<---------- Not null
Fred
Administrator
Administrator
Posts: 18264
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Re: (4.40b2 x86) GetProcAddress_() returns wrong value

Post by Fred »

You need to free the UTF8() result somewhere
Post Reply