【发布时间】:2020-10-14 12:18:40
【问题描述】:
我想在 c# 代码中使用 C++ dll 示例(使用 c++ dll):
class Program
{
[DllImport(@"netcoreapp3.1\savedecrypter.dll", CallingConvention = CallingConvention.Cdecl)]
public static extern string decryptSave(string o);
static void Main(string[] args)
{
string ja = "dhsabdasji";
string show = decryptSave(ja);
Console.WriteLine(show);
Console.ReadLine();
}
}
**and this is the EXAMPLE C++ dll code(im just a newbie in c++ btw)**
extern "C"
{
__declspec(dllexport) string decryptSave(string path21)
{
return path21;
}
}
尝试调用它时出错 “System.DllNotFoundException:'无法加载 DLL'netcoreapp3.1\savedecrypter.dll' 或其依赖项之一:找不到指定的模块。(0x8007007E)'” 谁能帮我解决这个问题?如果有人可以这样做,将不胜感激。
编辑:现在我启用了本机代码调试,它显示此错误:
未处理的异常:System.AccessViolationException:试图读取或写入受保护的内存。这通常表明其他内存已损坏。
【问题讨论】:
-
也许只是
@"savedecrypter.dll"? -
您是否尝试将 savedecrypter.dll 的位置添加到系统路径中然后只是 @"savedecrypter.dll"?
-
尝试使用绝对路径或使用两个 '\\'。此外,我不确定您的 dll 是否会执行预期的操作。请看stackoverflow.com/questions/32991274/…