【发布时间】:2014-02-21 16:28:35
【问题描述】:
我有一个 dllimport 的问题,首先是 C++ 代码:
extern "C" {
__declspec(dllexport) int wmain(char* configr, char* path)
{
ILoggerPtr logger;
try
{
_bstr_t config(configr);
_bstr_t srcFile(path);
}
我的 C# 代码:
[DllImport(@"Test.dll")]
static extern int wmain(string config, string path);
对 C++ 的呼吁:
string path = "c:\\bmp\\" + im.ID_MOVIMENTO + "_gray.bmp";
temp.Save(path, System.Drawing.Imaging.ImageFormat.Bmp);
int k = wmain("Brasil", path);
好的,问题,在 C++ char* 到 _bstr_t 的第一次转换中出现错误: CarregadorFotos.exe 中出现“System.AccessViolationException”类型的未处理异常
有人知道如何处理这个错误吗?
【问题讨论】:
-
又一个缺少 CallingConvention.Cdecl 的案例
-
对不起朋友,但不工作,现在在函数的开头抛出异常。
-
CarregadorFotos.exe 中发生了“System.AccessViolationException”类型的未处理异常附加信息:试图读取或写入受保护的内存。这通常表明其他内存已损坏。线程“Win32 线程”(0x738) 已退出,代码为 0 (0x0)。