I have a DLL with this function signature:
function KP_RecuperarDadosFabricante(EnderecoIp, ChaveAcesso,
Porta: string; Return: PAnsiChar): Integer; stdcall; external 'Key.dll';
This is the sample VB.NET code from the manual of the dll:
Dim ret As Integer
Dim ptrStr As IntPtr
Dim DadosFab As String
ptrStr = System.Runtime.InteropServices.Marshal.AllocHGlobal(256)
ret = KP_RecuperarDadosFabricante("192.168.1.201", "0", "4370", ptrStr)
DadosFab = System.Runtime.InteropServices.Marshal.PtrToStringAnsi(ptrStr)
System.Runtime.InteropServices.Marshal.FreeHGlobal(ptrStr)
This is my Delphi code:
procedure TForm1.BitBtn1Click(Sender: TObject);
var
Return: string;
pReturn: PAnsiChar;
begin
GetMem(pReturn, 512);
FillChar(pReturn^, 512, 0);
Memo1.Text:='';
if KP_RecuperarDadosFabricante("192.168.1.201", "0", "4370", pReturn) = 1 then
begin
Return := StrPas(pReturn);
ShowMessage(Return);
end
else
begin
ShowMessage('Error');
end;
end;
This code works well in Delphi 7, but not works in Delphi XE. It always returns "Error". How to make this code works in Delphi XE?