Hi to all,
I've moved a lot of code from BDS2006 to Sydney and now it's time to finish DLL interfacing.
Support DLLs are at moment in AnsiString so input parameters are as PAnsiChar, but overall calling
code is ready to use Unicode strings (I'm waiting the right time to convert the DLL).
When strings are emptied a nil pointer must be sent to DLL arguments.
As a workaround I've two solutions, one fine to see but I don't know if will work in all cases.
The second way could work fine always:
{ first mode }
function StringToAnsiCPointer(const S: string): PAnsiChar; inline;
function StringToAnsiCPointer(const S: string): PAnsiChar;
begin
if Length(S) = 0 then
Result := nil
else
Result := PAnsiChar(AnsiString(S));
end;
function CompilerEncryptFile(const TextFileName: string; Key: TCNCEncryptKey; const EncryptedFileName: string): Longint;
begin
Result := _CompilerEncryptFile // DLL CALL
(
StringToAnsiCPointer(TextFileName),
@Key,
StringToAnsiCPointer(EncryptedFileName)
);
end;
{ SECOND MODE }
function CompilerEncryptFile(const TextFileName: string; Key: TCNCEncryptKey; const EncryptedFileName: string): Longint;
begin
Result := _CompilerEncryptFile
(
IIf(Length(TextFileName) = 0, nil, PAnsiChar(AnsiString(TextFileName))),
@Key,
IIf(Length(EncryptedFileName) = 0, nil, PAnsiChar(AnsiString(EncryptedFileName)))
);
end;
My dubs in the first mode are concerning the LIFE of temporary cast to AnsiString in the line:
PAnsiChar(AnsiString(S) as a result of the external function.
Do you have some ideas about it?