These are a C DLL function example and its Delphi translation:
C definition:
DLL_EXPORT int AR_dll_function (const char *terminal_no, const char *description);
Delphi definition:
function Ar_Dll_Function(const TerminalNo: PAnsiChar; const Description: PAnsiChar):Integer;
...
function Ar_Dll_Function(const TerminalNo: PAnsiChar; const Description: PAnsiChar):Integer;
var
MyFunct : function(const TerminalNo: PAnsiChar; const Description: PAnsiChar):Integer;cdecl;
begin
Result := 0;
@MyFunct:=GetProcAddress(HInst,'ar_dll_function');
if Assigned(MyFunct) then
Result := MyFunct(TerminalNo, Description);
end;
I use the above Delphi function like this:
function SP(const s:string): PAnsiChar;
var
UTF8Str: RawByteString;
begin
Result := #0;
SetCodePage(UTF8Str, 0, False);
UTF8Str := UTF8Encode(s);
Result := PAnsiChar(AnsiString(UTF8Str));
end;
...
result := Ar_Dll_Function(SP(dTermNo),SP(descr));
The problem is between the two PAnsiChar
parameters. When I go into the DLL function in debug mode, I see that the second PAnsiChar
usually is the same as the first parameter, or the same as the function name:
//parameter examples in string :
dtermno:='AT0000058863'; descr:='NAKİT';
//parameter examples in PAnsiChar :
TerminalNo:='AT0000058863'; const Description:='AT0000058863'; //or
TerminalNo:='AT0000058863'; const Description:='ar_dll_function';
How can I solve the problem?