PROCEDURE TForm4.TestShlWAPISHAnsiToAnsi(Sender : TObject);
//Support for function as ordinal 345 under Win 98 SE (with IE 5.0) confirmed !!!
//Support for function as ordinal 345 under NT 4.0 with IE 5.0 confirmed !!!
VAR srcansibuf : STRING;
VAR srcstrlen : INTEGER;
VAR destansibuf : ARRAY[0..64] OF CHAR;
VAR destbufsize : INTEGER;
VAR apiretval : INTEGER;
VAR errorcode : INTEGER;
VAR newinfoline : STRING;
BEGIN
srcansibuf := '';
srcstrlen := 0;
FillChar(destansibuf, Length(destansibuf), #0);
destbufsize := 0;
apiretval := 0;
errorcode := 0; //0 = NO_ERROR
newinfoline := '';
SetLastError(NO_ERROR);
//errorcode := INTEGER(GetLastError()); //uncomment to verify that the last error PRIOR to any function call is 0
srcansibuf := 'Hello ANSI to ANSI World';
srcstrlen := Length(srcansibuf);
destbufsize := Length(destansibuf);
newinfoline := 'SHAnsiToAnsi called with source string "' + srcansibuf + '" (length: ' + IntToStr(srcstrlen) +
') returned : ';
//errorcode := INTEGER(GetLastError()); //uncomment to determine the last error prior to the function call
SetLastError(NO_ERROR);
apiretval := SHAnsiToAnsi(PChar(srcansibuf), destansibuf, destbufsize);
//errorcode := INTEGER(GetLastError()); //uncomment to determine the last error after the function call
IF apiretval > 0 THEN
newinfoline := newinfoline + IntToStr(apiretval) + ' and in the dest buffer : "' + destansibuf + '"'
ELSE
BEGIN
errorcode := INTEGER(GetLastError());
newinfoline := newinfoline + IntToStr(apiretval) + ' (the function call FAILED !), GetLastError returned : ' +
IntToStr(errorcode);
END;
Memo1.Lines.Add(newinfoline);
//errorcode := INTEGER(GetLastError()); //uncomment to determine the last error after the function call
//Dest buffer length parameter set to 17 (too short by 7 character)
FillChar(destansibuf, SizeOf(destansibuf), #0);
destbufsize := 17;
apiretval := 0;
newinfoline := '';
errorcode := 0;
newinfoline := 'SHAnsiToAnsi called with source string "' + srcansibuf + '" (length: ' + IntToStr(srcstrlen) +
') returned : ';
SetLastError(NO_ERROR); //uncomment to ensure that the last error PRIOR to the function call is 0
apiretval := SHAnsiToAnsi(PChar(srcansibuf), destansibuf, destbufsize);
//errorcode := INTEGER(GetLastError()); //uncomment to determine the last error after the function call
IF apiretval > 0 THEN
BEGIN
errorcode := INTEGER(GetLastError());
newinfoline := newinfoline + IntToStr(apiretval) + ' and in the dest buffer : "' + destansibuf + '"';
Memo1.Lines.Add(newinfoline);
newinfoline := 'and GetLastError returned : ' + IntToStr(errorcode);
END
ELSE
BEGIN
errorcode := INTEGER(GetLastError());
newinfoline := newinfoline + IntToStr(apiretval) + ' (the function call FAILED !), GetLastError returned : ' +
IntToStr(errorcode);
END;
Memo1.Lines.Add(newinfoline);
//Dest buffer length parameter set to 2 (too short by 23 characters)
FillChar(destansibuf, SizeOf(destansibuf), #0);
destbufsize := 2;
apiretval := 0;
newinfoline := '';
errorcode := 0;
newinfoline := 'SHAnsiToAnsi called with source string "' + srcansibuf + '" (length: ' + IntToStr(srcstrlen) +
') returned : ';
SetLastError(NO_ERROR);
apiretval := SHAnsiToAnsi(PChar(srcansibuf), destansibuf, destbufsize);
IF apiretval > 0 THEN
BEGIN
errorcode := INTEGER(GetLastError());
newinfoline := newinfoline + IntToStr(apiretval) + ' and in the dest buffer : "' + destansibuf + '"';
Memo1.Lines.Add(newinfoline);
newinfoline := 'and GetLastError returned : ' + IntToStr(errorcode);
END
ELSE
BEGIN
errorcode := INTEGER(GetLastError());
newinfoline := newinfoline + IntToStr(apiretval) + ' (the function call FAILED !), GetLastError returned : ' +
IntToStr(errorcode);
END;
Memo1.Lines.Add(newinfoline);
//Dest buffer length parameter set to 1 (too short by 24 characters)
FillChar(destansibuf, SizeOf(destansibuf), #0);
destbufsize := 1;
apiretval := 0;
newinfoline := '';
errorcode := 0;
newinfoline := 'SHAnsiToAnsi called with source string "' + srcansibuf + '" (length: ' + IntToStr(srcstrlen) +
') returned : ';
SetLastError(NO_ERROR);
apiretval := SHAnsiToAnsi(PChar(srcansibuf), destansibuf, destbufsize);
IF apiretval > 0 THEN
BEGIN
errorcode := INTEGER(GetLastError());
newinfoline := newinfoline + IntToStr(apiretval) + ' and in the dest buffer : "' + destansibuf + '"';
Memo1.Lines.Add(newinfoline);
newinfoline := 'and GetLastError returned : ' + IntToStr(errorcode);
END
ELSE
BEGIN
errorcode := INTEGER(GetLastError());
newinfoline := newinfoline + IntToStr(apiretval) + ' (the function call FAILED !), GetLastError returned : ' +
IntToStr(errorcode);
END;
Memo1.Lines.Add(newinfoline);
//Dest buffer length parameter set to 0
FillChar(destansibuf, SizeOf(destansibuf), #0);
destbufsize := 0;
apiretval := 0;
newinfoline := '';
errorcode := 0;
newinfoline := 'SHAnsiToAnsi called with source string "' + srcansibuf + '" (length: ' + IntToStr(srcstrlen) +
') returned : ';
SetLastError(NO_ERROR);
apiretval := SHAnsiToAnsi(PChar(srcansibuf), destansibuf, destbufsize);
IF apiretval > 0 THEN
newinfoline := newinfoline + IntToStr(apiretval) + ' and in the dest buffer : "' + destansibuf + '"'
ELSE
BEGIN
errorcode := INTEGER(GetLastError());
newinfoline := newinfoline + IntToStr(apiretval) + ' (the function call FAILED !), GetLastError returned : ' +
IntToStr(errorcode);
END;
Memo1.Lines.Add(newinfoline);
//No dest buffer (pointer param set to NIL)
//and buffer length parameter set to 0
FillChar(destansibuf, SizeOf(destansibuf), #0);
destbufsize := 0;
apiretval := 0;
newinfoline := '';
errorcode := 0;
newinfoline := 'SHAnsiToAnsi called with source string "' + srcansibuf + '" (length: ' + IntToStr(srcstrlen) +
') returned : ';
SetLastError(NO_ERROR);
apiretval := SHAnsiToAnsi(PChar(srcansibuf), NIL, 0);
IF apiretval > 0 THEN
newinfoline := newinfoline + IntToStr(apiretval) + ' and in the dest buffer : "' + destansibuf + '"'
ELSE
BEGIN
errorcode := INTEGER(GetLastError());
newinfoline := newinfoline + IntToStr(apiretval) + ' (the function call FAILED !), GetLastError returned : ' +
IntToStr(errorcode);
END;
Memo1.Lines.Add(newinfoline);
Memo1.Lines.Add('');
END; |
SHAnsiToAnsi called with source string "Hello ANSI to ANSI World" (length: 24)
returned : 25 and in the dest buffer : "Hello ANSI to ANSI World"
SHAnsiToAnsi called with source string "Hello ANSI to ANSI World" (length: 24)
returned : 0 (the function call FAILED !), GetLastError returned : 0
SHAnsiToAnsi called with source string "Hello ANSI to ANSI World" (length: 24)
returned : 0 (the function call FAILED !), GetLastError returned : 0
SHAnsiToAnsi called with source string "Hello ANSI to ANSI World" (length: 24)
returned : 0 (the function call FAILED !), GetLastError returned : 0
SHAnsiToAnsi called with source string "Hello ANSI to ANSI World" (length: 24)
returned : 0 (the function call FAILED !), GetLastError returned : 0
SHAnsiToAnsi called with source string "Hello ANSI to ANSI World" (length: 24)
returned : 0 (the function call FAILED !), GetLastError returned : 0 |