c#包装到c++函数-运行一次,工作正常.运行两次,程序挂起
C# wrapper to C++ function - Run once, works okay. Run twice, program hangs
所以我正在使用c#包装器到c++库,并试图添加另一个函数。我已经在c#中创建了函数声明,它正在工作。但它只能工作一次。当我第二次尝试运行它时,程序挂起了。
互操作定义和声明在https://github.com/joshglenn/interception-cs/blob/master/kchordr/Program.cs
我正在运行的代码在这里:https://github.com/joshglenn/interception-cs/blob/master/kchordr/InterceptionDemoForm.cs
第一次运行良好,但在第二次启动时挂起的函数是GetHardwareID()。
我的问题是,我如何解决这个问题?这看起来像是内存泄漏吗?
使用Marshal.GetLastWin32Error()从WinAPI调用中获取错误代码;还要记住用"Set Last Error = true"修饰调用;
下面是我调用任务栏图标弹出的一个例子:
[DllImport("shell32.dll",SetLastError=true)]
public static extern bool Shell_NotifyIcon(uint dwMessage, [In] ref NotifyIconData pnid);
用法:
//call your code like you usually call the method
bool callResult = Caller.Shell_NotifyIcon((uint)NotifyIconMessage.NIM_ADD, ref n);
//afther that call the GetLastError to get the error code
int errorCode = Marshal.GetLastWin32Error();
谷歌错误代码,看看它是什么意思
相关文章:
- Realloc 两次无法在 Visual Studio 上运行
- 谷歌测试发现在macOSX上添加并运行了我的所有测试两次
- C++:链接库两次,全局构造函数运行两次吗?
- 程序在运行两次后关闭
- *char数组到字符串(两次运行代码和两个不同的结果)
- 析构函数在 lambda 捕获说明符中声明的类实例上运行两次
- Cmake并需要两次运行才能成功构建代码
- 为什么输入文件的最后一行运行两次?
- c++ Google 测试运行两次
- Linux 守护进程 - 运行函数两次
- 我找不到导致我的数组在运行两次案例并退出后损坏的错误
- cmake 不会设置MPI_C_LIBRARIES,除非它运行两次
- 当循环应该只运行一次时,执行两次while循环(C++)
- 为什么这个C++/OpenGL程序运行两次
- 我的C++ Unity 插件在编辑器中运行一次,但不能运行两次
- 连续运行两次后的 scons 行为
- 函数在控制台中运行两次
- C++程序 尝试连续运行两次写入循环时显示".. stopped working"错误
- 如果同时运行两次wkhtmltopdf库,为什么它只会发生数据文档,而没有任何表或图像显示在html文件中
- c#包装到c++函数-运行一次,工作正常.运行两次,程序挂起