Problem with calling usbpt104.dll from managed C#

Post your .Net discussions here
Post Reply
Xandolph
Newbie
Posts: 0
Joined: Thu Apr 02, 2015 9:20 am

Problem with calling usbpt104.dll from managed C#

Post by Xandolph » Thu Apr 02, 2015 9:34 am

Hi!

I'm writing a wrapper in C# for the usbpt104.dll.
I can open the device via ethernet, set channels, read data and close the device without any problems.
But I'm still having a problem with the UsbPt104GetUnitInfo method. It keeps throwing a PInvokeStackImbalance.
Here's my import:

Code: Select all

        
[DllImport("UsbPT104.dll", SetLastError = true)]
private static extern PICO_STATUS UsbPt104GetUnitInfo(short handle, String information, int stringLength, ref int requiredSize, long info);

That's how i call the method:

Code: Select all

String info = "";
int requiredSize = 0;
PICO_STATUS status = UsbPt104GetUnitInfo(handle, info, 255, ref requiredSize, 4);

What am I doing wrong?
Thanks for your help!

Hitesh
Site Admin
Site Admin
Posts: 2793
Joined: Tue May 31, 2011 3:43 pm
Location: St. Neots, Cambridgeshire

Re: Problem with calling usbpt104.dll from managed C#

Post by Hitesh » Thu Apr 02, 2015 3:22 pm

Hi Xandolph,

Try using the StringBuilder class instead of a String.

Also check the data types for the requiredSize and info parameters.

You can find examples of defining similar functions in our oscilloscope SDK C# examples e.g. for the PicoScope 3204D.

Regards,
Hitesh

Technical Support Engineer

Post Reply