{$DEFINE SST_SHLWAPIVER6PT0VISTA}
{$IFDEF SST_SHLWAPIVER6PT0VISTA}
PROCEDURE TForm4.TestShlWAPIStrFormatByteSizeEx(Sender : TObject);
VAR filehandle : HFILE;
VAR sizetofmt : ULARGE_INTEGER;
VAR fmtflags : SFBS_FLAGS;
VAR sizestrbuf : ARRAY[0 .. 127] OF WideChar;
VAR bufsize : UINT;
VAR apiretval : HRESULT;
VAR newinfoline : STRING;
BEGIN
filehandle := 0;
FillChar(sizetofmt, SizeOf(sizetofmt), #0);
fmtflags := 0;
FillChar(sizestrbuf, SizeOf(sizestrbuf), #0);
bufsize := 0;
apiretval := S_OK; //S_OK = 0
newinfoline := '';
FillChar(sizestrbuf, SizeOf(sizestrbuf), #0);
fmtflags := 0;
bufsize := 0;
apiretval := StrFormatByteSizeEx(sizetofmt, fmtflags, sizestrbuf, bufsize);
newinfoline := sizestrbuf;
Memo1.Lines.Add(newinfoline);
filehandle := CreateFile('C:\Windows\System32\comctl32.dll', GENERIC_READ, FILE_SHARE_READ OR FILE_SHARE_WRITE, NIL,
OPEN_EXISTING, 0, 0);
sizetofmt.LowPart := GetFileSize(filehandle, @sizetofmt.HighPart);
newinfoline := 'StrFormatByteSizeEx called with ' + IntToStr(Int64(sizetofmt));
Memo1.Lines.Add(newinfoline);
bufsize := Length(sizestrbuf);
fmtflags := SFBS_FLAGS_ROUND_TO_NEAREST_DISPLAYED_DIGIT;
apiretval := StrFormatByteSizeEx(sizetofmt, fmtflags, sizestrbuf, bufsize);
newinfoline := sizestrbuf;
Memo1.Lines.Add(newinfoline);
FillChar(sizestrbuf, SizeOf(sizestrbuf), #0);
fmtflags := SFBS_FLAGS_TRUNCATE_UNDISPLAYED_DECIMAL_DIGITS;
apiretval := StrFormatByteSizeEx(sizetofmt, fmtflags, sizestrbuf, bufsize);
newinfoline := sizestrbuf;
Memo1.Lines.Add(newinfoline);
CloseHandle(filehandle);
FillChar(sizestrbuf, SizeOf(sizestrbuf), #0);
sizetofmt.QuadPart := $1;
newinfoline := 'StrFormatByteSizeEx called with ' + IntToStr(Int64(sizetofmt));
Memo1.Lines.Add(newinfoline);
bufsize := Length(sizestrbuf);
fmtflags := SFBS_FLAGS_ROUND_TO_NEAREST_DISPLAYED_DIGIT;
apiretval := StrFormatByteSizeEx(sizetofmt, fmtflags, sizestrbuf, bufsize);
newinfoline := sizestrbuf;
Memo1.Lines.Add(newinfoline);
FillChar(sizestrbuf, SizeOf(sizestrbuf), #0);
sizetofmt.QuadPart := $FEDC;
newinfoline := 'StrFormatByteSizeEx called with ' + IntToStr(Int64(sizetofmt));
Memo1.Lines.Add(newinfoline);
bufsize := Length(sizestrbuf);
fmtflags := SFBS_FLAGS_ROUND_TO_NEAREST_DISPLAYED_DIGIT;
apiretval := StrFormatByteSizeEx(sizetofmt, fmtflags, sizestrbuf, bufsize);
newinfoline := sizestrbuf;
Memo1.Lines.Add(newinfoline);
FillChar(sizestrbuf, SizeOf(sizestrbuf), #0);
sizetofmt.QuadPart := $D000CBA1;
newinfoline := 'StrFormatByteSizeEx called with ' + IntToStr(Int64(sizetofmt));
Memo1.Lines.Add(newinfoline);
bufsize := Length(sizestrbuf);
fmtflags := 0;//Note that the flags param is set to zero !
apiretval := StrFormatByteSizeEx(sizetofmt, fmtflags, sizestrbuf, bufsize);
newinfoline := sizestrbuf;
Memo1.Lines.Add(newinfoline);
FillChar(sizestrbuf, SizeOf(sizestrbuf), #0);
sizetofmt.QuadPart := $D000CBA1;
newinfoline := 'StrFormatByteSizeEx called with ' + IntToStr(Int64(sizetofmt));
Memo1.Lines.Add(newinfoline);
bufsize := Length(sizestrbuf);
fmtflags := SFBS_FLAGS_ROUND_TO_NEAREST_DISPLAYED_DIGIT;
apiretval := StrFormatByteSizeEx(sizetofmt, fmtflags, sizestrbuf, bufsize);
newinfoline := sizestrbuf;
Memo1.Lines.Add(newinfoline);
FillChar(sizestrbuf, SizeOf(sizestrbuf), #0);
sizetofmt.QuadPart := $D000CBA1;
newinfoline := 'StrFormatByteSizeEx called with ' + IntToStr(Int64(sizetofmt));
Memo1.Lines.Add(newinfoline);
bufsize := Length(sizestrbuf);
fmtflags := SFBS_FLAGS_TRUNCATE_UNDISPLAYED_DECIMAL_DIGITS;
apiretval := StrFormatByteSizeEx(sizetofmt, fmtflags, sizestrbuf, bufsize);
newinfoline := sizestrbuf;
Memo1.Lines.Add(newinfoline);
FillChar(sizestrbuf, SizeOf(sizestrbuf), #0);
sizetofmt.QuadPart := $D000CBA1;
newinfoline := 'StrFormatByteSizeEx called with ' + IntToStr(Int64(sizetofmt));
Memo1.Lines.Add(newinfoline);
bufsize := Length(sizestrbuf);
fmtflags := SFBS_FLAGS_ROUND_TO_NEAREST_DISPLAYED_DIGIT OR SFBS_FLAGS_TRUNCATE_UNDISPLAYED_DECIMAL_DIGITS;
apiretval := StrFormatByteSizeEx(sizetofmt, fmtflags, sizestrbuf, bufsize);
newinfoline := sizestrbuf;
Memo1.Lines.Add(newinfoline);
FillChar(sizestrbuf, SizeOf(sizestrbuf), #0);
sizetofmt.QuadPart := $100F000F000F;
newinfoline := 'StrFormatByteSizeEx called with ' + IntToStr(Int64(sizetofmt));
Memo1.Lines.Add(newinfoline);
bufsize := Length(sizestrbuf);
fmtflags := SFBS_FLAGS_ROUND_TO_NEAREST_DISPLAYED_DIGIT;
apiretval := StrFormatByteSizeEx(sizetofmt, fmtflags, sizestrbuf, bufsize);
newinfoline := sizestrbuf;
Memo1.Lines.Add(newinfoline);
FillChar(sizestrbuf, SizeOf(sizestrbuf), #0);
sizetofmt.QuadPart := $1000000000000000;
newinfoline := 'StrFormatByteSizeEx called with ' + IntToStr(Int64(sizetofmt));
Memo1.Lines.Add(newinfoline);
bufsize := Length(sizestrbuf);
fmtflags := SFBS_FLAGS_ROUND_TO_NEAREST_DISPLAYED_DIGIT;
apiretval := StrFormatByteSizeEx(sizetofmt, fmtflags, sizestrbuf, bufsize);
newinfoline := sizestrbuf;
Memo1.Lines.Add(newinfoline);
Memo1.Lines.Add('');
END;
{$ENDIF} |