Allan

Allan

  • NA
  • 4
  • 0

Calling an unmanaged C++ DLL with C#

Dec 8 2005 12:18 PM
Fairly newbie question here. I'm using a C++ DLL with a struct definition typedef struct _DEVICE { char DriveName[2048]; char DevicePath[7]; int HostId; int TargetId; }DEVICES; and I want to call the following method int OffLineSDK_GetDeviceList(DEVICES* pDeviceList) In C# code I have as an imort and struct definition using System.Runtime.InteropServices; [StructLayout(LayoutKind.Explicit)] public struct Device { [FieldOffset(0)] public char DriveName; [FieldOffset(2048)] public char DevicePath; [FieldOffset(2052)] public Int32 HostId; [FieldOffset(2056)] public Int32 TargetId; } Am just unsure of how to initialize the proper method call and parameter...something like the following but am unsure of the parameter to create and pass [DllImport("OffLineSDK.dll", CharSet=CharSet.Auto)] private static extern int OffLineSDK_GetDeviceList(...);