[fpc-pascal]When to use pointers with win32

Marco van de Voort marcov at stack.nl
Mon Nov 25 00:35:08 CET 2002

> but if the procedure is declared as:
> ‘Procedure someproc(var data: sometype)'
> the the pointer to the data will be passed.
> Whereas in C, you can only pass values to the procedure (or function). Of
> course it is possible to pass the pointer, but then you have to know this,
> when calling the procedure. Your program line must be ‘someproc(&data)' for
> passing the pointer.
> When I read the documentation of the windows API, for each parameter in any
> function it tells me whether I should pass the value or the pointer. So in
> case of writing a C-program, there is no problem. But when using Pascal
> with the win32 unit, I think it must be different. It would be a little
> weird and agaist the beauty of Pascal to define a lot of pointers to be
> used with this unit.

We also fell for this trap, but in general it is wisest to keep the pointers.
This because many win32 (and also POSIX) routines accept a NIL pointer as special
value (often meaning something like use default for this parameter).

> So my guess is that the win32 unit has been
> constructed as to use Pascal style procedure calls, so that
> ‘someproc(data)' sometimes pass the pointer to the data, namely when the
> API wants the pointer. But does that always hold?
> In the examples that comes with the Free Pascal installation, I have seen
> that sometimes the address operator @ is used in a call to a procedure in
> the win32 unit.
> So my question is: How can I know when to use the data identifier and when
> to use an address or pointer in a call to a procedure in the win32 unit?

Check the source of the definition. Most are pointers, but some are not
because Delphi decided to use const and var.

If you really hate the C specifications of the win32 api, try to find the
(somewhat old) win32 helpfile on the Borland site. I don't have an URL since
they frequently reorder things.

More information about the fpc-pascal mailing list