這可能會或可能無法正常工作。你可以試試,我不知道我是否正確處理了指針。我無法爲此提供任何其他支持。如果它有效,那麼它就可以工作。如果不是那麼......哦,好吧。
//typedef struct UIclient_info {
// char name[50];
// int age;
// SECONDUSER *stParent;
//} FIRSTUSER;
[StructLayout(LayoutKind.Sequential, CharSet=CharSet.Ansi)]
public struct FirstUser
{
[MarshalAs(UnmanagedType.ByValTStr, SizeConst=50)]
public string Name;
public int Age;
[MarshalAs(UnmanagedType.LPStruct)]
public IntPtr Parent;
}
//typedef struct ui_product_form {
// char m_sCoupon;
// double amountTotal;
// char m_sErrorCode[50];
// SUBPRODUCT *pstSubProduct;
//} PRODUCT;
[StructLayout(LayoutKind.Sequential, CharSet=CharSet.Ansi)]
public struct Product
{
public char Coupon;
public double AmountTotal;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst=50)]
public string ErrorCode;
[MarshalAs(UnmanagedType.LPStruct)]
public IntPtr SubProduct;
}
//typedef struct tagReport
//{
// REPORTSUMMARY *pstRepsum;
// char errorMsg[100];
//} FINAL_REPORT;
[StructLayout(LayoutKind.Sequential, CharSet=CharSet.Ansi)]
public struct FinalReport
{
[MarshalAs(UnmanagedType.LPStruct)]
public IntPtr ReportSummary;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst=100)]
public string ErrorMsg;
}
static class MyLibraryHelper
{
//int Save(FIRSTUSER *myUser, PRODUCT *uiStructure);
[DllImport(@"MyLibrary.dll", CharSet=CharSet.Ansi)]
internal static extern int Save(IntPtr myUser, IntPtr uiStructure);
//FINAL_REPORT GenerateReport(FIRSTUSER *myUser, PRODUCT *uiStructure);
[DllImport(@"MyLibrary.dll", CharSet=CharSet.Ansi)]
internal static extern FinalReport GenerateReport(IntPtr myUser, IntPtr uiStructure);
}