我正在尝试将一个加密函数从我们的遗留代码中分离到一个dll中,我可以从C#中调用这个dll,但是我在使它正常工作时遇到了问题,并且在调用dll时一直存在访问冲突。
我不知道AV在哪里发生,因为delphi在dll附加到另一个进程时很难击中我的断点。
我昨天用大卫·赫弗南( David )的答案-- 在64位中将delphi中的字符串返回给C#调用方 --让它工作了,但我的成功是短暂的,因为我把字符串参数改成了普通的string
's (delphi),发现它不起作用,并将它们改为AnsiString
(我们的加密程序期望Ansi)。因为我改变了这些param类型,我一直没能让它再次工作。
这是我的Delphi代码:
procedure Encrypt(const Source: AnsiString; const Key: AnsiString; var OutPut:PAnsiChar; const OutputLength: Integer);
var
EncryptedString, EncodedString: AnsiString;
begin
EncryptedString := Crypt(Source, Key);
EncodedString := Encode(EncryptedString);
if Length(EncodedString) <= OutputLength then
System.AnsiStrings.StrPCopy(Output, EncodedString);
end;
exports
Encrypt;
我的C#来电者:
[DllImport("AsmEncrypt.dll", CharSet = CharSet.Ansi)]
public static extern void Encrypt(string password, string key, StringBuilder output, int outputlength);
// using like this:
Encrypt(credentials.Password, myKey, str, str.Capacity);
我现在最好的选择是,我已经忽略了dll的一些参数,因为它似乎在到达OutputDebugStr()
之前就崩溃了,我把dll放在了Encrypt()
的第一行
我们将非常感谢所有的帮助。
https://stackoverflow.com/questions/69552512
复制相似问题