我的结构在C中看起来像这样
typedef struct drive_info_t {
unsigned char drive_alias[32];
} drive_info_t;
Run Code Online (Sandbox Code Playgroud)
我的功能在C中看起来像这样
unsigned int get_drive_info_list(drive_info_t **list, unsigned int *item_count) {
//fill list in native C
//print out in native C
printf("list.alias - %s\r\n",list[i]->drive_alias);
}
Run Code Online (Sandbox Code Playgroud)
我的C#struct看起来像这样
[StructLayout(LayoutKind.Sequential)]
public struct drive_info_t
{
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 32)]
public byte[] drive_alias;
}
Run Code Online (Sandbox Code Playgroud)
我的C#函数声明如下所示
[DllImport("mydll.dll", EntryPoint = "get_drive_info_list", CallingConvention = CallingConvention.Cdecl)]
public static extern uint GetDriveInfoList(out System.IntPtr ptr_list_info, out System.IntPtr ptr_count);
Run Code Online (Sandbox Code Playgroud)
我正在这样调用C#函数
IntPtr ptr_list_info = IntPtr.Zero;
IntPtr ptr_cnt = IntPtr.Zero;
ret = …Run Code Online (Sandbox Code Playgroud)