Hi, I’m writing my GUI in C# and using okFrontPanel.dll. My wires and triggers are working properly but I’m having trouble with with the pipe. Here’s the relevant pieces of code followed by the error I’m getting.
unsafe class XEM
{
//…
[DllImport(“okFrontPanel.Dll”)]
public static extern long okUsbFrontPanel_ReadFromPipeOut(int handle, int epAddr, long length, byte *data);
//…
}
this builds fine but when I actually get to this spot in the program it hangs and gives me this error:
A call to PInvoke function ‘FDS!XEM::okUsbFrontPanel_ReadFromPipeOut’ has unbalanced the stack. This is likely because the managed PInvoke signature does not match the unmanaged target signature. Check that the calling convention and parameters of the PInvoke signature match the target unmanaged signature.
Well I found the problem… I was so sure that it was something to do with the pointer that I didn’t really pay attention to the other parameters. Turns out long in C++ is 32 bits but in C# is 64 bits so I changed the prototype to:
[DllImport(“okFrontPanel.Dll”)]
public unsafe static extern int okUsbFrontPanel_ReadFromPipeOut(int handle, int epAddr, int length, byte *data);
I was able to get the device count respond correctly using the above, so I am sure that the dll is loaded and running, I think my problem is on the char pointer… Can someone help me?