StrFormatByteSize unicode? 5.00

Windows specific forum
Justin
Addict
Addict
Posts: 959
Joined: Sat Apr 26, 2003 2:49 pm

StrFormatByteSize unicode? 5.00

Post by Justin »

This code only works in ansi, in unicode crashes

Code: Select all

procedure.s FormatByteSize(size.q)
	define.s{32} res
	
  StrFormatByteSize_(size, @res, 32)
  
  procedurereturn res
endprocedure

debug FormatByteSize(1000)
XP SP3
User avatar
ts-soft
Always Here
Always Here
Posts: 5756
Joined: Thu Jun 24, 2004 2:44 pm
Location: Berlin - Germany

Re: StrFormatByteSize unicode? 5.00

Post by ts-soft »

confirmed for x86, not for x64
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
nco2k
Addict
Addict
Posts: 1344
Joined: Mon Sep 15, 2003 5:55 am

Re: StrFormatByteSize unicode? 5.00

Post by nco2k »

those functions are a bit tricky. StrFormatByteSizeA requires a long for the size parameter and StrFormatByteSizeW requires a quad. if you want to use a quad for the size parameter in ascii mode, you have to use StrFormatByteSize64A. note that there is no StrFormatByteSize64W and therefore you have to use StrFormatByteSizeW in unicode mode:

Code: Select all

Import "Shlwapi.lib"
  CompilerSelect #PB_Compiler_Processor
    CompilerCase #PB_Processor_x86
      CompilerIf #PB_Compiler_Unicode
        StrFormatByteSize64_(qdw.q, *pszBuf, cchBuf.l) As "_StrFormatByteSizeW"
      CompilerElse
        StrFormatByteSize64_(qdw.q, *pszBuf, cchBuf.l) As "_StrFormatByteSize64A"
      CompilerEndIf
    CompilerCase #PB_Processor_x64
      CompilerIf #PB_Compiler_Unicode
        StrFormatByteSize64_(qdw.q, *pszBuf, cchBuf.l) As "StrFormatByteSizeW"
      CompilerElse
        StrFormatByteSize64_(qdw.q, *pszBuf, cchBuf.l) As "StrFormatByteSize64A"
      CompilerEndIf
  CompilerEndSelect
EndImport

Procedure$ FormatByteSize(Size.q)
  Protected Result$, Buffer${11}
  If StrFormatByteSize64_(Size, @Buffer$, 11)
    Result$ = Buffer$
  EndIf
  ProcedureReturn Result$
EndProcedure

Debug FormatByteSize(2047)
c ya,
nco2k
If OSVersion() = #PB_OS_Windows_ME : End : EndIf
Justin
Addict
Addict
Posts: 959
Joined: Sat Apr 26, 2003 2:49 pm

Re: StrFormatByteSize unicode? 5.00

Post by Justin »

Thanks, it works now.
Post Reply