[fpc-pascal]Win32 API Call
tom_at_work at yline.com
Sat Dec 8 14:58:48 CET 2001
> > But is that why you're using the @ symbol for BytesFree? Somehow I get
> > feeling you're going to tell me no. And if you do, then how come the
> > Reference says all the values are pularge_integer but only ones need to
> > referenced by it's address?
> [error in redef.inc]
>This is not equivalent to what Windows expects: the first two parameters,
>lpFreeBytesAvailableToCaller and lpTotalNumberOfBytes are declared as
>untyped var parameters (generic pointers), while the third parameter,
>lpTotalNumberOfFreeBytes is a pointer to a large integer. The Win32 API, in
>contrast to this, specifies all three parameters as pointers to large
>integers, hence the need to change the semicolon after lpTotalNumberOfBytes
>to a comma.
Well, but you forget that the third param is optional, e.g. can be nil.
>If this is corrected, you don't have to use the '@' operator before the
>third parameter any more.
No, because the third parameter is optional, e.g. can be null. By using a
'var' parameter you'd force the programmer to always declare a (probably
dummy-) variable for the third param which limits your options to use that
function. A completely correct translation for the Pascal language (imo):
function GetDiskFreeSpaceEx(lpDirectoryName: PChar; var
lpFreeBytesAvailableToCaller, lpTotalNumberOfBytes : LargeInteger;
lpTotalNumberOfFreeBytes: PLargeInteger): BOOL;external 'kernel32' name
This forces the programmer to use a large integer as mentioned in the MS
docs for the first two params but still allows for 'nil' for the third param
and preserving the option to ignore the result of lpTotalNumberOfFreeBytes,
e.g. not requiring you to declare never used dummy variables in your calling
More information about the fpc-pascal