dll错误:试图读取或写入受保护的内存
c# DllImport c++ dll error: Attempted to read or write protected memory
下面是我的c++代码:
ExportAPI.cpp
extern "C"
{
EXPORT_API int test(int a, int b){
return a*b;
}
EXPORT_API bool InitializeApplication( HWND hwnd)
{
CCEGLView::SetParentHwnd(hwnd);
CCApplication::sharedApplication()->run();
return true;
}
}
c#: public partial class MainWindow : Window
{
[DllImport("libcc.dll", CallingConvention=CallingConvention.Cdecl)]
public static extern bool InitializeApplication(IntPtr hwnd);
[DllImport("libcc.dll", CallingConvention = CallingConvention.Cdecl)]
public static extern int test(int a, int b);
public MainWindow()
{
InitializeComponent();
Loaded += MainWindow_Loaded;
Closed += MainWindow_Closed;
}
void MainWindow_Loaded(object sender, RoutedEventArgs e)
{
Window window = Window.GetWindow(this);
var wih = new WindowInteropHelper(window);
Debug.WriteLine(Multiply(3, 4).ToString()); //this runs
InitializeApplication(wih.Handle); //this gives error
}
}
所以基本上我要做的是将WPF窗口设置为我的c++应用程序的父窗口(我在.dll中"打包")。但是当我运行时,我得到"附加信息:试图读取或写入受保护的内存。"这通常表明其他内存已损坏。"
对不起,我的英语不好。任何帮助都非常感谢!听起来像是CCEGLView::SetParentHwnd(hwnd);
或CCApplication::sharedApplication()->run();
的bug。启用本机代码调试以查找问题的根源。
相关文章:
- 公共/私有/受保护是否会更改内存中结构的排列?
- 检查nullptr是否100%保护内存布局不受segfault影响
- 如何编辑受保护的进程内存?
- C 写入具有受保护内存的过程
- 尝试读取或写入受保护的内存.这通常表示其他内存已损坏.在C++Dll中
- 当值到指针时,尝试读取或写入受保护的内存
- C#调用C++dll试图读取或写入受保护的内存
- 在 C# 中加载非托管C++.错误 尝试读取或写入受保护的内存
- 尝试读/写受保护的内存错误,同时固定 c++ 函数
- 试图读取或写入受保护的内存:C++修改的内存值
- 已尝试读取或写入受保护的内存.这通常表示其他内存已损坏 DllImport
- 试图在 c# 访问 c++ dll 时读取或写入受保护的内存错误
- 未处理的异常:系统.访问违规异常:尝试读取或写入受保护的内存
- 通过 DllImport 在 C# 中调用 C 方法 - 尝试读取或写入受保护的内存
- P/在 /MT 或 /MD 上调用"受保护的内存"异常
- System.AccessViolationException试图读取或写入受保护的内存
- C++.NET包装程序:试图读取或写入受保护的内存.这通常表示其他内存已损坏
- 系统.AccessViolationException:试图在c++ dll中读写受保护的内存
- 附加信息:试图读取或写入受保护的内存.这通常表明其他内存已损坏
- dll错误:试图读取或写入受保护的内存