【发布时间】:2010-03-28 18:19:32
【问题描述】:
当尝试从具有带有 requireAdministrator 清单文件的 .net 应用程序调用 (DLLImport) 外部 c++ dll 时,在启用 UAC 的 Windows 7 中尝试从 C++ dll 调用函数时遇到此错误。
我调用的方法:EnCrypts
例外:
System.AccessViolationException:试图读或写保护 记忆。这通常表明其他内存已损坏。
代码:
public class BlowFish
{
[DllImport("BlowfishTool.dll", CharSet = CharSet.Auto)]
public static extern String EnCrypt(String strData, String strPassword);
[DllImport("BlowfishTool.dll", CharSet = CharSet.Auto)]
public static extern String EnCrypt(String strData, String strPassword, bool doNotUsePassChecking);
[DllImport("BlowfishTool.dll", CharSet = CharSet.Auto)]
public static extern String DeCrypt(String strData, String strPassword, bool doNotUsePassChecking);
[DllImport("BlowfishTool.dll", CharSet = CharSet.Auto)]
public static extern String DeCrypt(String strData, String strPassword);
public static String EnCrypts(String strData, String strPassword)
{
return EnCrypt(strData, strPassword, true);
}
}
【问题讨论】:
-
Manifest 和 UAC 在这里无关紧要。该错误提示声明(参数、返回值、数据类型等)有问题,或者 dll 本身存在某种内存损坏。你能发布这些函数的 C++ 声明吗?
标签: c#