scrypt-for-delphi
scrypt-for-delphi copied to clipboard
"Incompatible types: 'PWideChar' and 'Pointer'" in call of FormatMessage()
The call to FormatMessage()
can only be compiled with {$TYPEDADDRESS OFF}
. Otherwise
https://github.com/JackTrapper/scrypt-for-delphi/blob/f5d05ba4f735e407dd00cc8a54388b82da2d182d/SCrypt.pas#L430-L438
will result in a compiler error: [dcc32 Error] SCrypt.pas(438): E2010 Incompatible types: 'PWideChar' and 'Pointer'
(translated from German). This is due to @Buffer
being a pointer to PChar
while FormatMessage()
formally expects a PChar
, though because of the combination of flags provided in the first parameter the provided pointer is actually treated as a pointer to PChar
internally.
There are two solutions to this problem:
- Put a
{$TYPEDADDRESS OFF}
at the top of the unit, or - put a typecast around
@Buffer
, i.e.,PChar(@Buffer)
I think the second solution is preferrable, because it makes the special handling of this argument more explicit.