I have an API written in C++ and am attempting to use this with interop in C# Windows forms. I am having difficulty defining the equivalent C# struct. Here is the C++ struct:
typedef struct
{
char SerNo[LENGTH];
HANDLE dev;
} myDevice;
Edit:
Thanks to the comments the first item is solved. Here is the current C# status:
public unsafe struct sdrplay_api_DeviceT
{
[MarshalAsAttribute(UnmanagedType.ByValTStr, SizeConst = 64)]
string SerNo;
public IntPtr dev;
}
However nothing I try get's the HANDLE. So I guess at this time, I will expand on the code further:
In the original C++ code, there is a function as follows:
GetDevices(myDevice *devs);
and in the C# code I have done this:
public unsafe static extern GetDevices([In, Out] myDevice[] devs);
Now the code I use is as follows:
myDevice[] devs = new myDevice[6];
var error = GetDevices(devs);
If I look at devs in Visual Studio I see the SerNo (devs[0].SerNo) correctly but the "handle is always 0;
I tried IntPtr, byte, but I am at a loss. Thanks, Tom