Board index » delphi » ReadConsole 32-bit API

ReadConsole 32-bit API

I'm trying to create a Delphi 2.0 console application, but I can't
get the ReadConsole api as defined by the windows.pas unit to work.

WINDOWS.PAS api declaration:
===========================
function ReadConsole(hConsoleInput: THandle; lpBuffer: Pointer;
  nNumberOfCharsToRead: DWORD; var lpNumberOfCharsRead: DWORD; lpReserved:
Pointer): BOOL; stdcall;

Here are my declarations:
------------------------

var
  STDIN, CONTENT_LENGTH: Word;
  ENV_CONTENT_LENGTH: string;
  buffer: pchar;
  bytesread: dword;
  lpvReserved: Pointer;
  success:bool;
begin
  ENV_CONTENT_LENGTH:= GetEnvVar('content_length');  //Get Environment
  CONTENT_LENGTH:= strtoint(ENV_CONTENT_LENGTH);     //Variables
  STDIN:= GetStdHandle(STD_INPUT_HANDLE);            //Get Console Handle
  lpvReserved:= nil;                                 //Set pointer to nil
  Success:= ReadConsole(STDIN,Buffer,CONTENT_LENGTH,@bytesRead,lpvReserved);
end;

When I try to compile this, I get the following error message:
Types of actual and formal var parameters must be identical & it positions
the cursor on the last parameter - lpvReserved.

Can someone please tell me what I'm doing wrong?  Please e-mail me if you
can help.

Regards,
Minh Tran
e-mail: minh.v.t...@mci.com

 

Re:ReadConsole 32-bit API


Quote
k...@bay.edu (kato) wrote:
>I'm trying to create a Delphi 2.0 console application, but I can't
>get the ReadConsole api as defined by the windows.pas unit to work.
>WINDOWS.PAS api declaration:
>===========================
>function ReadConsole(hConsoleInput: THandle; lpBuffer: Pointer;
>  nNumberOfCharsToRead: DWORD; var lpNumberOfCharsRead: DWORD; lpReserved:
>Pointer): BOOL; stdcall;
>Here are my declarations:
>------------------------
>var
>  STDIN, CONTENT_LENGTH: Word;
>  ENV_CONTENT_LENGTH: string;
>  buffer: pchar;
>  bytesread: dword;
>  lpvReserved: Pointer;
>  success:bool;
>begin
>  ENV_CONTENT_LENGTH:= GetEnvVar('content_length');  //Get Environment
>  CONTENT_LENGTH:= strtoint(ENV_CONTENT_LENGTH);     //Variables
>  STDIN:= GetStdHandle(STD_INPUT_HANDLE);        //Get Console Handle
>  lpvReserved:= nil;                                     //Set pointer to nil
>  Success:= ReadConsole(STDIN,Buffer,CONTENT_LENGTH,@bytesRead,lpvReserved);
>end;
>When I try to compile this, I get the following error message:
>Types of actual and formal var parameters must be identical & it positions
>the cursor on the last parameter - lpvReserved.
>Can someone please tell me what I'm doing wrong?  Please e-mail me if you
>can help.

You problem is with the "@bytesRead" parameter. As it is already a var
parameter, you don't need to use the @ (address) operator. Leave it
away, and everything is fine.

Regards,

Jani J?rvinen
a.k.a SilverStream Software
Helsinki Finland

Tools, information, tips, reviews & bug lists
for professional Delphi, Win32 and WinHelp developers.

mailto:ja...@dystopia.fi
http://www.dystopia.fi/~janij/

Other Threads