blackbiscuit said:
Dear all,
May I ask whether there is any tool to help people to automatically
transfer C++ struct into C# struct?
Thank you very much!
Best Regards,
Tony
Tony, take a look at P/Invoke Interop Assistance utility.
http://msdn.microsoft.com/en-us/magazine/cc164193.aspx
It does a pretty good job and generating a translation for C/C++
structures and functions.
Example:
struct MyStruct {
int f1;
char *sz[255];
} ;
bool xyz(MyStruct *p);
generates:
[System.Runtime.InteropServices.StructLayoutAttribute(System.Runtime.InteropServices.LayoutKind.Sequential)]
public struct MyStruct {
/// int
public int f1;
/// char*[255]
[System.Runtime.InteropServices.MarshalAsAttribute(System.Runtime.InteropServices.UnmanagedType.ByValArray,
SizeConst=255,
ArraySubType=System.Runtime.InteropServices.UnmanagedType.SysUInt)]
public System.IntPtr[] sz;
}
public partial class NativeMethods {
/// Return Type: boolean
///p: MyStruct*
[System.Runtime.InteropServices.DllImportAttribute("<Unknown>",
EntryPoint="xyz")]
[return:
System.Runtime.InteropServices.MarshalAsAttribute(System.Runtime.InteropServices.UnmanagedType.I1)]
public static extern bool xyz(ref MyStruct p) ;
}
--