5
我很難找出讓delphi函數對.net的字節數組進行操作的最佳方法。從C#調用delphi dll函數傳遞一個字節數組
Delphi的簽名如下所示:
procedure Encrypt(
var Bytes: array of byte;
const BytesLength: Integer;
const Password: PAnsiChar); stdcall; export;
的C#代碼如下所示:
[DllImport("Encrypt.dll",
CallingConvention = CallingConvention.StdCall,
CharSet = CharSet.Ansi)]
public static extern void Encrypt(
ref byte[] bytes,
int bytesLength,
string password);
字節數組聲明之前忽略var
和ref
似乎失敗了,但因爲需要它我只會改變數組的內容而不是數組本身?
此外,由於某種原因,我似乎無法獲得在Delphi中數組的長度,如果我刪除BytesLength
參數比Length(Bytes)
將無法正常工作,如果我添加了BytesLength
參數,Length(Bytes)
開始工作,但BytesLength
有錯誤的價值。