Page 1 of 1
[5.0 b7] GetProcAddress does not work with unicode mode
Posted: Sun Oct 28, 2012 7:17 pm
by codeprof
Test with and without unicode compiler switch:
Code: Select all
handle = GetModuleHandle_("user32.dll")
Debug GetProcAddress_(handle, "MessageBoxA")
Re: [5.0 b7] GetProcAddress does not work with unicode mode
Posted: Sun Oct 28, 2012 7:36 pm
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!
Re: [5.0 b7] GetProcAddress does not work with unicode mode
Posted: Sun Oct 28, 2012 7:52 pm
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...
Re: [5.0 b7] GetProcAddress does not work with unicode mode
Posted: Sun Oct 28, 2012 8:01 pm
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
This is a WinAPI-Limitation by microsoft
Re: [5.0 b7] GetProcAddress does not work with unicode mode
Posted: Mon Oct 29, 2012 12:21 am
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.
Re: [5.0 b7] GetProcAddress does not work with unicode mode
Posted: Tue Oct 30, 2012 11:11 am
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.
Re: [5.0 b7] GetProcAddress does not work with unicode mode
Posted: Mon Oct 28, 2013 6:00 pm
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