Board index » delphi » Is there a Delphi equivalent of typedef const void *VariableType

Is there a Delphi equivalent of typedef const void *VariableType

I'm trying to use some dll's written in C++. The headers have the
following type definitions and function

typedef void *ANE_PTR;
typedef const void *ANE_CPTR;

ANE_CPTR ANE_LayerGetCurrent(ANE_CPTR handle);

Right now my Delphi equivalent is

type
  ANE_PTR = Pointer;

function ANE_LayerGetCurrent(const handle: ANE_PTR): ANE_PTR;

Is this adequate. I'm worried about that the return type of the
function (ANE_PTR) is not the same as the original return type
(ANE_CPTR).

 

Re:Is there a Delphi equivalent of typedef const void *VariableType


In article <35ccfc97.20230...@news.mindspring.com>,
rbwins...@no.spam.mindspring.com (Richard B. Winston) writes:

Quote
>I'm worried about that the return type of the
>function (ANE_PTR) is not the same as the original return type
>(ANE_CPTR).

It is the same type, just that the C++ compiler and Pascal compiler are going
to treat it differently. You may as well say (for the sake of closeness to the
C++ )prototype

type
  ANE_PTR = Pointer;
  ANE_CPTR = ANE_PTR;

function ANE_LayerGetCurrent(const handle: ANE_CPTR): ANE_CPTR;

As far as I know, there is no way for a Pascal datatype to be able to receive
an assignment at runtime, and yet be told that it cannot be changed thereafter.
You're getting as close as you can with const handle.
It'll be fine

Charles Johnson

Re:Is there a Delphi equivalent of typedef const void *VariableType


Quote
Richard B. Winston wrote in message

<35ccfc97.20230...@news.mindspring.com>...

Quote
>I'm trying to use some dll's written in C++. The headers have the
>following type definitions and function

>typedef void *ANE_PTR;
>typedef const void *ANE_CPTR;

>ANE_CPTR ANE_LayerGetCurrent(ANE_CPTR handle);

>Right now my Delphi equivalent is

>type
>  ANE_PTR = Pointer;

>function ANE_LayerGetCurrent(const handle: ANE_PTR): ANE_PTR;

>Is this adequate?

Probably not - but not for the reason you think. You haven't told Delphi
which calling convention your C++ DLL is using and so Delphi will use its
default of "register". Tell Delphi and your DLL to use the "stdcall"
convention instead.

Don't worry about the difference between ANE_PTR and ANE_CPTR because they
are both pointers. However, as I understand it, the above Delphi-translation
is not correct (although it will work and the error is harmless).

In C++, "const void *" means that you only have read-access to the
DEREFERENCED memory, whereas in Delphi "const p: Pointer" means that you
cannot modify the pointer itself. Delphi has no support for *typed*
constant-reference pointers, which is a shame considering that pointer
operations are among the most error-prone in any language.

Chris.

Other Threads