【发布时间】:2013-10-28 09:57:20
【问题描述】:
我想使用 Delphi 制作的 dll。它有这个功能: 函数 CryptStr(str, Key : AnsiString; DecryptStr : boolean) : AnsiString;标准调用;
我将 Dll 复制到 /bin/debug 和应用程序根目录中。我的代码是:
[DllImport("Crypt2.dll", EntryPoint = "CryptStr", CallingConvention = CallingConvention.StdCall)]
static extern string CryptStr( string str, string Key, bool DecryptStr);
public string g = "";
private void Form1_Load(object sender, EventArgs e)
{
g=CryptStr("999", "999999", true);
MessageBox.Show(g);
}
我有一些问题: 1. 即使我从那些路径应用程序中删除 Dll 也不会抛出未找到的异常 2. 当应用程序运行在 g=CryptStr("999", "999999", true);它完成执行并显示表单而不运行 Messagebox 行。 我尝试使用 Marshal,但仍然存在上述错误。
【问题讨论】:
-
Form 吞下 Load 事件中的任何异常。您需要在事件中自己处理。所以添加一个适当的 try..catch。