So I am working with a c# wrapper to a C++ library, and trying to add another function. I have created the function declaration in C# and it is working. But it only works once. When I try to run it the second time, the program hangs.
The interop definitions and declarations are at https://github.com/joshglenn/interception-cs/blob/master/kchordr/Program.cs
the code I am running is here: https://github.com/joshglenn/interception-cs/blob/master/kchordr/InterceptionDemoForm.cs
The function that runs fine the first time but hangs on the second launch is GetHardwareID().
My question is, how can I troubleshoot this? Does this appear to be a memory leak?
to get the error code from the WinAPI call use the Marshal.GetLastWin32Error(); Also remember to decorate your call with "Set Last Error = true";
Here is an example i have for calling a popup on a taskbar icon :
[DllImport("shell32.dll",SetLastError=true)]
public static extern bool Shell_NotifyIcon(uint dwMessage, [In] ref NotifyIconData pnid);
usage:
//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 the error code and see what it means