I have a Delphi 2010 DLL that will be used to compress some data from a C# APP. The DLL function looks like this:
function CompressString(aInputString: PAnsiChar; aInputStringSize: Integer;
var aOutPutString: PAnsiChar; var aOutPutStringSize: Integer;
var aErrorMsgBuffer: PAnsiChar; var aErrorMsgBufferSize: integer): Integer;
stdcall; export;
The C# method looks like this:
[DllImport("MyDLL.dll", CallingConvention=CallingConvention.StdCall, CharSet=CharSet.Ansi)]
public static extern int CompressString(string aInputString,
int aInputStringSize, ref string aOutPutString,
out int aOutPutStringSize, ref string aErrorMsgBuffer,
out int aErrorMsgBufferSize);
My problem is that aOutPutString is being truncated, only part of the data is being seen by the C# App. If I change aOutPutString inside the Delphi DLL to be a simple literal constant (only for testing) it works fine.
Inside the DLL, I am working with strings. In the end of the function, I call:
StrPCopy(aOutPutString, vOutOutAnsiStr);
To convert an AnsiString do PAnsiChar.
I guess I should not be using PAnsiChar but an array of byte, but I am not sure how to do that.
byte[]would seem to be the most natural.