当前位置:编程学习 > C#/ASP.NET >>

求助:C#调用 dll of delphi 嵌套结构的问题

delphi 结构体
1.
TStringOfChar = array [0..99] of char;
2.
TPersonInfo = record
//以下数据为返回数据
PSN_ID      :   Integer;      //医疗参保ID号
    PSN_No      :   Integer; //参保人编码
    PSN_NAME    :   TStringOfChar;//参保人姓名
    Sex         :   TStringOfChar;//性别
IDCARD      :   TStringOfChar;//身份证号码
    PSN_STS     :   TStringOfChar;//参保人状态
    PSN_TYP     :   TStringOfChar;//人员类别
    UNIT_CODE   :   TStringOfChar;//单位编码
    UNIT_NAME   :   TStringOfChar;//单位名称
    OFFICAL_TYP :   TStringOfChar;//公务员类别
    HAI_TYP     :   TStringOfChar;//补充医保名称
    ACCT_STS    :   TStringOfChar;//医保账户状态
    HI_ACCT_PWD :   TStringOfChar;//医保帐户口令
    SILL_PAY_AMT_TOTAL :   Single;//年内进入门诊特殊疾病支付金额
    SILL_YR_FUND_AMT   :   Single;//年内门诊统筹基金支付金额
    YR_FUND_AMT        :   Single;//年内统筹基金支付金额
    HAI_YR_HIGH_AMT    :   Single;//年内补充高额支付金额
    HAI_YR_INBED_AMT   :   Single;//年内补充住院补助支付金额
    GZ_CUR_AMT         :   Single;//个人账户余额
YR_INBED_CNT       :  integer;//年内住院次数 
Card_No     :   TStringOfChar;//IC卡卡号
end;
delphi 函数
1.
function CheckValid(var strNo: TStringOfChar;//字符串测试
  var Int : Integer ;  //整数测试
  var Money : Single ;  //浮点数测试
  var PsnInfo : TPersonInfo   //记录结构测试
  ) : Boolean; export; stdcall;
2.
procedure GetErrorMessage(var AErrorMsg: TStringOfChar); export; stdcall;
=========================================================================================
C# 结构体
1.
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
    public class StringOfChar
    {
        [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 100)]
        public string pchr;
    }
2.
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
    public class S_PersonInfo
    {
        //以下数据为返回数据
        public int PSN_ID;                  //医疗参保ID号
        public int PSN_No;             //参保人编码
        //[MarshalAs(UnmanagedType.Struct)]
        public StringOfChar PSN_NAME;             //参保人姓名
        //[MarshalAs(UnmanagedType.Struct)]
        public StringOfChar Sex;                  //性别
        //[MarshalAs(UnmanagedType.Struct)]
        public StringOfChar IDCARD;               //身份证号码
        //[MarshalAs(UnmanagedType.Struct)]
        public StringOfChar PSN_STS;              //参保人状态
        //[MarshalAs(UnmanagedType.Struct)]
        public StringOfChar PSN_TYP;              //人员类别
        //[MarshalAs(UnmanagedType.Struct)]
        public StringOfChar UNIT_CODE;            //单位编码
        //[MarshalAs(UnmanagedType.Struct)]
        public StringOfChar UNIT_NAME;            //单位名称
        //[MarshalAs(UnmanagedType.Struct)]
        public StringOfChar OFFICAL_TYP;          //公务员类别
        //[MarshalAs(UnmanagedType.Struct)]
        public StringOfChar HAI_TYP;              //补充医保名称
        //[MarshalAs(UnmanagedType.Struct)]
        public StringOfChar ACCT_STS;             //医保账户状态
        //[MarshalAs(UnmanagedType.Struct)]
        public StringOfChar HI_ACCT_PWD;          //医保帐户口令
        public float SILL_PAY_AMT_TOTAL;    //年内进入门诊特殊疾病支付金额
        public float SILL_YR_FUND_AMT;      //年内门诊统筹基金支付金额
        public float YR_FUND_AMT;           //年内统筹基金支付金额
        public float HAI_YR_HIGH_AMT;       //年内补充高额支付金额
        public float HAI_YR_INBED_AMT;      //年内补充住院补助支付金额
        public float GZ_CUR_AMT;            //个人账户余额
        public int YR_INBED_CNT;            //年内住院次数 
        //[MarshalAs(UnmanagedType.Struct)]
        public StringOfChar Card_No;              //IC卡卡号
    }
C# 函数
1.
[DllImport("SIHisInte易做图ce.dll", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
        public static extern bool CheckValid([Out]StringOfChar strNo, [Out] int i, [Out] float f, [Out] S_PersonInfo pInfo);
2.
[DllImport("SIHisInte易做图ce.dll", CallingConvention = CallingConvention.StdCall)]
        public static extern void GetErrorMessage([Out] StringOfChar ErrorMsg);//获取最后一次错误的信息
===================================================================================
问题描述:GetErrorMessage()能够顺利获取错误信息,但是CheckValid()始终报错误<<尝试读取或写入受保护的内存。这通常指示其他内存已损坏。>>,下面是调用CheckValid()的代码,应该不是未初始造成的错误。
 D_AYYB_DZXH.StringOfChar strNo = new D_AYYB_DZXH.StringOfChar();
            strNo.pchr = "aaa";
            int i = 1;
            float f = 1f;
            D_AYYB_DZXH.S_PersonInfo pInfo = new D_AYYB_DZXH.S_PersonInfo();
            pInfo.PSN_ID = 1;                  //医疗参保ID号
            pInfo.PSN_No = 1;             //参保人编码
            pInfo.PSN_NAME = new D_AYYB_DZXH.StringOfChar();
            pInfo.Sex = new D_AYYB_DZXH.StringOfChar();
            pInfo.IDCARD = new D_AYYB_DZXH.StringOfChar();
            pInfo.PSN_STS = new D_AYYB_DZXH.StringOfChar();
            pInfo.PSN_TYP = new D_AYYB_DZXH.StringOfChar();
            pInfo.UNIT_CODE = new D_AYYB_DZXH.StringOfChar();
            pInfo.UNIT_NAME = new D_AYYB_DZXH.StringOfChar();
            pInfo.OFFICAL_TYP = new D_AYYB_DZXH.StringOfChar();
            pInfo.HAI_TYP = new D_AYYB_DZXH.StringOfChar();
            pInfo.ACCT_STS = new D_AYYB_DZXH.StringOfChar();
            pInfo.HI_ACCT_PWD = new D_AYYB_DZXH.StringOfChar();
            pInfo.Card_No = new D_AYYB_DZXH.StringOfChar();

            pInfo.PSN_NAME.pchr = ("aaa");
            pInfo.Sex.pchr = ("aaa");
            pInfo.IDCARD.pchr = ("aaa");
            pInfo.PSN_STS.pchr = ("aaa");
            pInfo.PSN_TYP.pchr = ("aaa");
            pInfo.UNIT_CODE.pchr = ("aaa");
            pInfo.UNIT_NAME.pchr = ("aaa");
            pInfo.OFFICAL_TYP.pchr = ("aaa");
            pInfo.HAI_TYP.pchr = ("aaa");
            pInfo.ACCT_STS.pchr = ("aaa");
            pInfo.HI_ACCT_PWD.pchr = ("aaa");
            pInfo.SILL_PAY_AMT_TOTAL = 0f;
            pInfo.SILL_YR_FUND_AMT = 0f;
            pInfo.YR_FUND_AMT = 0f;
            pInfo.HAI_YR_HIGH_AMT = 0f;
            pInfo.HAI_YR_INBED_AMT = 0f;
            pInfo.GZ_CUR_AMT = 0f;
            pInfo.YR_INBED_CNT = 1;
            pInfo.Card_No.pchr = ("aaa");
 bool result = D_AYYB_DZXH.Functions.CheckValid(strNo, i, f, pInfo); --------------------编程问答-------------------- 帮顶都没人
真凄凉
补充:.NET技术 ,  C#
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,