Link to home
Start Free TrialLog in
Avatar of lhl60
lhl60

asked on

useing readfileEx in Delphi 5

Hi there
I want to use simple overlapped I/O in Delphi 5
I've done it numerous times in Vs C++ so I know what to do,
I'm relatively in Delphi
And I have a syntax problem
compiler complains about  "not enough actual parameters"
See code below
I can't see the problem, can you ?
Regards Lars




type
  Tbuffer = packed array[0..1024] of byte;
 
type
    TMyoverlapped = class(Tobject)
    Data:tbuffer;
    overlapped:TOverlapped;
end;
 
// when posting a read  
// the Buffer will be deleted on completion
    Buffer:= TMyoverlapped.create;
    ReadFileEx(handle,@Buffer.data,1024,@buffer.overlapped,_onSerialData);
 
//completion routine
procedure Tmainwindow._onSerialdata(Errorcode:integer; NumberOfbytesReceived:integer; overlapped:TOverlapped);

Open in new window

Avatar of MerijnB
MerijnB
Flag of Netherlands image

is _onSerialdata a method of Tmainwindow? If so, it can't be, it has to be a 'normal' function.
Avatar of lhl60
lhl60

ASKER

Thanks,

Now I moved the onSerialdata to "global" scope, but I still get the "not enough parameters error"  on the ReadfileEx call

I count and I count but I see enough parameter of correct types

did you add stdcall ?

procedure _onSerialdata(Errorcode:integer; NumberOfbytesReceived:integer; overlapped:TOverlapped); stdcall;
does it work without the completion routine ?
like this:
https://www.experts-exchange.com/questions/20053566/ReadFile-ReadFileEx-API-calls.html?qid=20053566

and what line does the compiler give an error on ...
it may the error is in the line above sometimes
may this declaration will help in this reference:
http://ftp.escom.bg/Windows/winsite/JCL/jvcl/source/JvHidControllerClass.pas

look for ReadFileEx, you should find:

var
  // counter to prevent a second TJvHidDeviceController instance
  GlobalInstanceCount: Integer = 0;
 
//== these are declared inconsistent in Windows.pas ============================
 
function ReadFileEx(hFile: THandle; var Buffer; nNumberOfBytesToRead: DWORD;
  var Overlapped: TOverlapped; lpCompletionRoutine: TPROverlappedCompletionRoutine): BOOL; stdcall;
  external 'kernel32.dll' name 'ReadFileEx';
function WriteFileEx(hFile: THandle; var Buffer; nNumberOfBytesToWrite: DWORD;
  var Overlapped: TOverlapped; lpCompletionRoutine: TPROverlappedCompletionRoutine): BOOL; stdcall;
 external 'kernel32.dll' name 'WriteFileEx';

Open in new window

Avatar of lhl60

ASKER

Stdcall now added ( what was i thinking ?)
but still no change
And the error seems to be here

   ReadFileEx(handle,@Buffer.data,1024,@buffer.overlapped,onSerialData)
error:
"not enough actual parameters"

and without completion:

    ReadFile(handle,@Buffer.data,1024,@buffer.overlapped)
error:
"types of actual and formal parameters must be identical"
I suspect it has to do with the  @'s, My Delphi skills aren't that good
If you change the 'layout' of your code to like below, you might get more details on where in the arguments the compiler gives the error:
    ReadFileEx(handle,
               @Buffer.data,
               1024,
               @buffer.overlapped,
               _onSerialData);

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of MerijnB
MerijnB
Flag of Netherlands image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of lhl60

ASKER

Changing the line to :

    ReadFileEx(ComHandle,@Buffer.data,1024,@buffer.overlapped,@onSerialData);

fixed the compilations errors:

Now I just have to make it work

Closing the thread now
Thanks for you interest
rgds. Lars


Avatar of lhl60

ASKER

yes thank you