Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2002-03

Windows Console API

3 messages · 2 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Fernando Lozano

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

Fernando Lozano
to ron wilson

Hi Ron,

maybe 'msg2' is your problem? i don't see it defined... > WriteFile (stdout, msg2, length (msg), aux, nil);

I tried to use CharToOem and OemToChar (so msg2) but got nothing better. Please read "msg" and not "msg2".

[]s, Fernando Lozano