Search code examples
c++cdelphidelphi-7

How to pass C/C++ *(PUCHAR)(..) correctly?


I need to pass C/C++ code *(PUCHAR)(..) to delphi so I can use it with no errors but I don't know how exactly to do it. At the question I made in an IRC someone told me that "it cast to pointer to unsigned char and dereference that pointer but I don't think there is such a thing in Delphi".

Here is an example:

DWORD isENABLED;

...

*(PUCHAR)(isENABLED) = 0x00;

In Delphi will be like this?

PUCHAR(isENABLED) := $00;   // Is it right?

I know that this question might not be properly written but I don't know how exactly to ask this. Thanks for your help.


Solution

  • UCHAR is an unsigned char. That's Byte in Delphi. PUCHAR is pointer to UCHAR. That's PByte in Delphi.

    The original code casts the DWORD to be a pointer to unsigned char, then de-references that pointer, and assigns a value to that unsigned char.

    So the Delphi equivalent code is:

    PByte(isENABLED)^ := $00;
    

    If your Windows unit defines PUCHAR then feel free to write it as:

    PUCHAR(isENABLED)^ := $00;