[fpc-pascal]Windows Console API
    Fernando Lozano 
    fsl at centroin.com.br
       
    Fri Mar 15 16:24:10 CET 2002
    
    
  
Hi there,
Under Windows 98SE the following program works just fine:
program win32test;
uses windows;
var
    stdout : long;
    msg : AnsiString;
    aux : ulong;
    
begin
    stdout := GetStdHandle (STD_OUTPUT_HANDLE);
    msg := 'Win32 Console API';
    WriteConsole (stdout, PChar (msg), length (msg), aux, nil);
end.
But this one prints garbage on the screen:
program win32test;
uses windows;
var
    stdout : long;
    msg : AnsiString;
    aux : ulong;
    
begin
    stdout := GetStdHandle (STD_OUTPUT_HANDLE);
    msg := 'Win32 Console API';
    WriteFile (stdout, msg2, length (msg), aux, nil);
end.
I guess this happens because my strings are not Unicode.
The problem is, if my program uses WriteConsole instead of WriteFile, its standard output can't redirected. And I guess if I use WriteFile or ReadFile on a disk file I'll write or read garbage.
My question is: Which is the proper way to deal with file input and output and with Unicode strings from a Free Pascal program using the Win32 API?
[]s, Fernando Lozano
    
    
More information about the fpc-pascal
mailing list