Page 1 of 1

StrFormatByteSize unicode? 5.00

Posted: Tue Jan 01, 2013 12:04 pm
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

Re: StrFormatByteSize unicode? 5.00

Posted: Tue Jan 01, 2013 12:15 pm
by ts-soft
confirmed for x86, not for x64

Re: StrFormatByteSize unicode? 5.00

Posted: Tue Jan 01, 2013 12:59 pm
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

Re: StrFormatByteSize unicode? 5.00

Posted: Tue Jan 01, 2013 11:03 pm
by Justin
Thanks, it works now.