Dodgy header translation into Delphi?
From: Martin Harvey (Demon account) (martin_at_nospam_pergolesi.demon.co.uk)
Date: 10/31/04
- Next message: Martin Harvey (Demon account): "Re: Dodgy header translation into Delphi?"
- Previous message: Scott: "Closing another App..."
- Next in thread: Martin Harvey (Demon account): "Re: Dodgy header translation into Delphi?"
- Reply: Martin Harvey (Demon account): "Re: Dodgy header translation into Delphi?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Sat, 30 Oct 2004 22:58:13 GMT
Hmmm ... I've come across a bit of an oddity in the Delphi translation
of the Win32 headers....
MSDN says:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dllproc/base/setwaitabletimer.asp
BOOL SetWaitableTimer(
HANDLE hTimer,
const LARGE_INTEGER* pDueTime,
LONG lPeriod,
PTIMERAPCROUTINE pfnCompletionRoutine,
LPVOID lpArgToCompletionRoutine,
BOOL fResume
);
However, in Delphi 4 at least, this ends up translating into:
function SetWaitableTimer(hTimer: THandle; const lpDueTime:
TLargeInteger;
lPeriod: Longint; pfnCompletionRoutine: TFNTimerAPCRoutine;
lpArgToCompletionRoutine: Pointer; fResume: BOOL): BOOL; stdcall;
Which looks really a bit suspect. Why do I say this? Well, pDueTime
should definitely be a pointer. However, I was then able to write:
WaitableTimer := CreateWaitableTimer(nil, false, nil);
Assert(WaitableTimer <> 0);
SetWaitableTimer(WaitableTimer, 0, TIMER_PERIOD, nil, nil, false);
The problem is that I can write a constant zero into the second
parameter.
Now, there's likely to be plenty of const confusion here - but the
second parameter is meant to be a (variable in callee) pointer to a
constant large integer. (The MSDN docs don't quite seem clear to me as
to whether that pointer can be NULL).
However, Delphi has translated all this subtlety into "const". Well,
are constants passed by pointer or not? "var" parameters certainly
are, but I'm concerned that const parameters of 4 bytes or less may
not - because based on the percieved intent of the C declaration, I
would not expect to be able to pass a constant large integer value
into the function.
Of course, if it was really smart, the Delphi compiler might simply
allocate a zeroed 64 bit quantity in the data segment, and then pass a
pointer to that to the procedure ... but I'm not convinced it's going
to do that ... ;-)
Unfortunately, I won't be able to test this for a day or so until I've
written enough supporting code...
MH.
- Next message: Martin Harvey (Demon account): "Re: Dodgy header translation into Delphi?"
- Previous message: Scott: "Closing another App..."
- Next in thread: Martin Harvey (Demon account): "Re: Dodgy header translation into Delphi?"
- Reply: Martin Harvey (Demon account): "Re: Dodgy header translation into Delphi?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|