0

所以我正在使用 ac# 包装器到 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()。

我的问题是,我该如何解决这个问题?这似乎是内存泄漏?

4

1 回答 1

1

要从 WinAPI 调用中获取错误代码,请使用Marshal.GetLastWin32Error();还记得用“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();

google一下错误码看看是什么意思

于 2014-03-19T15:03:18.850 回答