(SST) ShlWAPI.pas Version 1.08

Developer Reference
(SST)ShlWAPI StrFormatByteSizeA Function
Converts the specifed, unsigned, 32 bit integer into a string that is a user friendly representation of its numerical value.
Global (i.e. this function can be called/accessed from code in any unit that includes/uses (SST)ShlWAPI.pas).
function StrFormatByteSizeA(dw : DWORD; szBuf : LPSTR; uiBufSize : UINT) : LPSTR;
dw [in] The unsigned, 32-bit, integer value to convert.
szBuf [out] A pointer to the buffer into which the zero-terminated, output string should be written.
uiBufSize [in] The size, including the terminating null character, in number of ANSI characters, of the buffer pointed to by szBuf.
Return Values
If the conversion succeeded, the function returns a pointer to the formatted, ANSI string, if it failed, it returns NIL.
This function differs from the wide character version (StrFormatByteSizeW) not only in the required string type, but also in the supported file size the first (parameter).
PROCEDURE TForm4.TestShlWAPIStrFormatByteSizeA(Sender : TObject);

VAR filehandle : HFILE;
VAR sizetoconvert : DWORD;
VAR sizestrbuf : ARRAY[0 .. 127] OF CHAR;
VAR bufsize : UINT;
VAR apiretpointer : PChar;
VAR newinfoline : STRING;

filehandle := 0;
sizetoconvert := 0;
bufsize := 0;
apiretpointer := NIL;
newinfoline := '';

filehandle := CreateFile('C:\Windows\explorer.exe', GENERIC_READ, FILE_SHARE_READ OR FILE_SHARE_WRITE, NIL, OPEN_EXISTING, 0, 0);
sizetoconvert := GetFileSize(filehandle, NIL);
newinfoline := 'StrFormatByteSizeA called with ' + IntToStr(sizetoconvert);
bufsize := Length(sizestrbuf);
apiretpointer := StrFormatByteSize(sizetoconvert, sizestrbuf, bufsize);
newinfoline := apiretpointer;

The above example ought to produce an output similar to that below.
StrFormatByteSizeA called with 2927104
2.79 MB
Unit: Declared and imported in (SST)ShlWAPI.pas
Library: (SST)ShlWAPI.dcu/(SST)ShlWAPI.obj
Unicode: Implemented as ANSI (StrFormatByteSize and StrFormatByteSizeA) and Unicode (StrFormatByteSizeW) functions.
Min. ShlWAPI.dll version according to MS SDK doc.: 4.71.
Min. ShlWAPI.dll version based on SST research: 4.71.
Min. OS version(s) according to Microsoft SDK doc.: Windows 2000, Windows NT 4.0 with Internet Explorer 4.0, Windows 98, Windows 95 with Internet Explorer 4.0.
Min. OS version(s) according to SST research.: Windows NT 4.0 with IE 4.0, Windows 95 with IE 4.0, Windows 98, Windows 2000 and later.
See Also
StrFormatByteSizeW, StrFormatByteSize64A, StrFormatKBSize.
Windows APIs: StrFormatByteSize, StrFormatByteSize64A, StrFormatByteSizeEx, StrFormatKBSize.

Document/Contents version 1.00
Page/URI last updated on 07.12.2023
Copyright © Stoelzel Software Technologie (SST) 2010 - 2017
Suggestions and comments mail to: