create unicode executable can't read api return string .

Just starting out? Need help? Post your questions and find answers here.
PureBoy
User
User
Posts: 17
Joined: Mon May 01, 2006 8:13 pm
Location: Urumqi China
Contact:

create unicode executable can't read api return string .

Post by PureBoy »

Structure MODULEENTRY32tmp

dwSize.l
th32ModuleID.l
th32ProcessID.l
GlblcntUsage.l
ProccntUsage.l
modBaseAddr.l
modBaseSize.l
hModule.l
szModule.s{256}
szExePath.s{260}
EndStructure

var
md.MODULEENTRY32tmp

the md\szExePath is null
if not unicode executable,md\szExePath will return a file path.
how to get string in the unicode mode.
help me!
which function can convert ansi to unicode or convert unicode to ansi.
sverson
Enthusiast
Enthusiast
Posts: 286
Joined: Sun Jul 04, 2004 12:15 pm
Location: Germany

Re: create unicode executable can't read api return string .

Post by sverson »

PureBoy wrote: which function can convert ansi to unicode or convert unicode to ansi.

Code: Select all

Structure MODULEENTRY32tmp
  dwSize.l
  th32ModuleID.l
  th32ProcessID.l
  GlblcntUsage.l
  ProccntUsage.l
  modBaseAddr.l
  modBaseSize.l
  hModule.l
  szModule.s{256}
  szExePath.s{260}
EndStructure

md.MODULEENTRY32tmp

md\szExePath="C:\TESTPATH\ASCII"
Debug md\szExePath
Debug @md\szExePath
PokeS(@md\szExePath,"C:\TESTPATH\UNICODE",-1,#PB_Unicode)
Debug md\szExePath ; just 1st char
Debug PeekS(@md\szExePath,-1,#PB_Unicode)

You may also take a look at these (API) Unicode and Character Set Functions:

GetTextCharset: Retrieves a character set identifier For the font that is currently selected into a specified device context.
GetTextCharsetInfo: Retrieves information about the character set of the font that is currently selected into a specified device context.
IsDBCSLeadByte: Determines whether a character is a lead byte.
IsDBCSLeadByteEx: Determines whether a character is a lead byte.
IsTextUnicode: Determines whether a Buffer is likely To contain a form of Unicode text.
MultiByteToWideChar: Maps a character string To a wide-character (Unicode) string.
TranslateCharsetInfo: Translates based on the specified character set, code page, Or font Signature Value.
WideCharToMultiByte: Maps a wide-character string To a new character string.
sverson
Enthusiast
Enthusiast
Posts: 286
Joined: Sun Jul 04, 2004 12:15 pm
Location: Germany

Post by sverson »

...some examples...

Code: Select all

Procedure.l Ansi2Unicode(Ansi.s)
  ;/ Ansi    [in]  Character string to be converted. 
  ;/ pointer [out] Points to a buffer that receives the translated (UNICODE) string.
  Protected AnsiLen.l, UniLen.l
  AnsiLen = Len(Ansi)
  UniLen = MultiByteToWideChar_(#CP_ACP, 0, Ansi, AnsiLen, 0, 0)
  If UniLen
    *Unicode = SysAllocStringLen_(0, UniLen)
    If MultiByteToWideChar_(#CP_ACP, 0, Ansi, AnsiLen, *Unicode, UniLen)
      ProcedureReturn *Unicode
    EndIf
  EndIf
  ProcedureReturn 0
EndProcedure

Procedure.s Unicode2Ansi(*Unicode,UniLen.l)
  ;/ *Unicode [in]  Points To the wide-character string To be converted. 
  ;/ UniLen   [in]  Specifies the number of wide characters in the string pointed to by the lpWideCharStr parameter. If this value is -1, the string is assumed to be null-terminated and the length is calculated automatically. The length will include the null-terminator.
  ;/ string   [out] The translated (ANSI) string.
  Protected Ansi.s,AnsiLen.l
  AnsiLen = WideCharToMultiByte_(#CP_ACP,0,*Unicode,UniLen,0,AnsiLen,0,0)
  If AnsiLen
    Ansi = Space(AnsiLen)
    If WideCharToMultiByte_(#CP_ACP,0,*Unicode,UniLen,@Ansi,AnsiLen,0,0);"•",#True)
      ProcedureReturn Ansi
    EndIf
  EndIf
  ProcedureReturn ""
EndProcedure


Test1.s = "TestText ANSI-UNICODE"
*Test2 = Ansi2Unicode(Test1)
Debug Unicode2Ansi(*Test2,-1)
CallDebugger
User avatar
blueznl
PureBasic Expert
PureBasic Expert
Posts: 6166
Joined: Sat May 17, 2003 11:31 am
Contact:

Post by blueznl »

( PB6.00 LTS Win11 x64 Asrock AB350 Pro4 Ryzen 5 3600 32GB GTX1060 6GB)
( The path to enlightenment and the PureBasic Survival Guide right here... )
sverson
Enthusiast
Enthusiast
Posts: 286
Joined: Sun Jul 04, 2004 12:15 pm
Location: Germany

Post by sverson »

blueznl wrote:unicode <> widechar !
Oh yes - you're right! :oops:

BTW - the Survival Guide is a great thing.
PureBoy
User
User
Posts: 17
Joined: Mon May 01, 2006 8:13 pm
Location: Urumqi China
Contact:

Post by PureBoy »

good!
PureBasic Super Designer
http://www.purebasic.cn/pbsd
VB6--->PB4
make pb4 form in vb6
Post Reply