[5.0 b7] GetProcAddress does not work with unicode mode

Windows specific forum
codeprof
User
User
Posts: 65
Joined: Sun Sep 16, 2012 12:13 pm

[5.0 b7] GetProcAddress does not work with unicode mode

Post by codeprof »

Test with and without unicode compiler switch:

Code: Select all

handle = GetModuleHandle_("user32.dll")
Debug GetProcAddress_(handle, "MessageBoxA")
User avatar
ts-soft
Always Here
Always Here
Posts: 5756
Joined: Thu Jun 24, 2004 2:44 pm
Location: Berlin - Germany

Re: [5.0 b7] GetProcAddress does not work with unicode mode

Post by ts-soft »

This is not a bug, the API doesn't support Unicode. Use GetFunction()
or Poke the functionname in a memory as ascii-string.
In functionnames no signs allowed, other than ASCII!
PureBasic 5.73 | SpiderBasic 2.30 | Windows 10 Pro (x64) | Linux Mint 20.1 (x64)
Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.
Image
codeprof
User
User
Posts: 65
Joined: Sun Sep 16, 2012 12:13 pm

Re: [5.0 b7] GetProcAddress does not work with unicode mode

Post by codeprof »

I think it is a bug, because PureBasic is doing some conversions automatically. At least it is confusing.
e.g. this works:

Code: Select all

a.f  = #MB_ICONWARNING
MessageBox_(0,"test","test",a)
PureBasic automatically convert the strings to pointers and it even converts float to integer...
User avatar
ts-soft
Always Here
Always Here
Posts: 5756
Joined: Thu Jun 24, 2004 2:44 pm
Location: Berlin - Germany

Re: [5.0 b7] GetProcAddress does not work with unicode mode

Post by ts-soft »

codeprof wrote: PureBasic automatically convert the strings to pointers and it even converts float to integer...
But PB uses MsgBoxW! There is no GetProcAddressW!

Import the Function with Pseudotype or poke ASCII-String in memory, but this is not a Bug :wink:
This is a WinAPI-Limitation by microsoft
PureBasic 5.73 | SpiderBasic 2.30 | Windows 10 Pro (x64) | Linux Mint 20.1 (x64)
Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.
Image
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8451
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Re: [5.0 b7] GetProcAddress does not work with unicode mode

Post by netmaestro »

I'm not sure I agree that it isn't a bug, the reason being that PureBasic imports API functions for immediate availability to the coder, and an import done like this:

Code: Select all

Import "kernel32.lib"
  GetProcAddress_(handle.l, string.p-ascii) As "_GetProcAddress@8"
EndImport

;Test it

handle = GetModuleHandle_("user32.dll")
Debug GetProcAddress_(handle, "MessageBoxA")
will work for either Ascii or Unicode compiler modes. This being the case, why doesn't PB just do the import like this and make it seamless? This could be seen as a bug if you look at it in this light.
BERESHEIT
Fred
Administrator
Administrator
Posts: 18162
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Re: [5.0 b7] GetProcAddress does not work with unicode mode

Post by Fred »

As it could be handled with prototypes, it wouldn't still allow unicode string which aren't in the ascii range. You are calling GetProcAddressA_() because the W_() version doesn't exists so you have to take care of that in unicode mode.
pablov
User
User
Posts: 19
Joined: Mon Apr 06, 2009 11:55 am

Re: [5.0 b7] GetProcAddress does not work with unicode mode

Post by pablov »

Code: Select all

Name_funcA.s = Space(#MAX_PATH)            ; Ascii
handle = GetModuleHandle_("user32.dll")
If handle
   CompilerIf #PB_Compiler_Unicode
     WideCharToMultiByte_(#CP_ACP, 0, @"MessageBoxA", -1, @Name_funcA, #MAX_PATH, #Null, #Null)
     Debug Hex(GetProcAddress_(handle, Name_funcA))
   CompilerElse
     Debug Hex(GetProcAddress_(handle, "MessageBoxA"))
   CompilerEndIf
EndIf
Post Reply