I am working on USB Bulk Transfer "lmusbdll.dll" with C# Language in Visual Studio.
I import DLL as below:
[DllImport("lmusbdll.dll", EntryPoint = "InitializeDevice", ExactSpelling = true, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
public static extern IntPtr InitializeDevice(ushort usVID, ushort usPID,ref System.Guid lpGUID, ref bool pbDriverInstalled);
I called Initialize function as below:
ushort BULK_VID = 0x1cbe;
ushort BULK_PID = 0x0003;
bool bDriverInstalled = false;
UInt32 ulRead = 0;
UInt32 pulWritten = 0;
IntPtr hBreak = IntPtr.Zero;
IntPtr hUSB = IntPtr.Zero;
// Create a GUID, match to what is in INF file
System.Guid GUID_DEVINTERFACE_LUMINARY_BULK;
GUID_DEVINTERFACE_LUMINARY_BULK = new System.Guid("{6E45736A-2B1B-4078-B772-B3AF2B6FDE1C}");
// Init the USB device
hUSB = InitializeDevice(BULK_VID, BULK_PID,ref GUID_DEVINTERFACE_LUMINARY_BULK, ref bDriverInstalled);
But I am getting error as below:
Managed Debugging Assistant 'PInvokeStackImbalance'
Message=Managed Debugging Assistant 'PInvokeStackImbalance' : 'A call to PInvoke function 'WindowsFormsApp1!WindowsFormsApp1.Form1::InitializeDevice' 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.'
Please help me or provide if any working code available.
Thanks in Advance!