0

関数に対して実行するときにc#で構築した構造体は、構造体に問題があることを示すエラーメッセージの1つを表示しません。ソースファイルが見つかりませんと表示されます。繰り返しますが、ドキュメントがないために、この DLL についてはあまり知りません。しかし、私は構造を間違って設定したためだとまだ考えています。ほとんどの場合、構造体内の構造体を参照している 3 番目の構造体を考えています。私が行った仕事についてのフィードバックを期待していました。助けてくれてありがとう。

これはCで提供されたものです:

int BatchTotal_Transactions(int transType, pTGiftCardReqBatchTotal req, pTGiftCardRespBatchTotal resp, int (*Com)(char *));

typedef struct _tagGiftCardReqBatchTotal
{
char Password[9];
char OperatorID[9];
char BatchNum[14];
char StartDate[11];
char EndDate[11];
unsigned char Type;
} TGiftCardReqBatchTotal, *pTGiftCardReqBatchTotal;


typedef struct _tagGiftCardRespBatchTotal
{
char Result;
char TerminalId[17];
unsigned char DispMsgControl;
char DispMsg[256];
char Display[41];
char Date[11];
char Time[9];
char RespCode[4];
char BatchNum[14];
char ErrorFlag;
char CustLang;
char UserLang;
char OpenDate[17];
char ClosedDate[17];
char StartDate[11];
char EndDate[11];
char BatchStatus;
int CardTypeNum;
TGiftCardTotals GctHost[MAX_CARD_CODES];
TGiftCardTotals GctTRS[MAX_CARD_CODES];
} TGiftCardRespBatchTotal, *pTGiftCardRespBatchTotal;

typedef struct _tagGiftCardTotals
{
unsigned short CardCode;
unsigned short PurchaseNum;
long PurchaseTotal;
unsigned short RefundNum;
long RefundTotal;
unsigned short RedemptionNum;
long RedemptionTotal;
unsigned short CorrectionNum;
long CorrectionTotal;
long PurchaseBenefitTotal;
long RefundBenefitTotal;
long RedemptionBenefitTotal;
} TGiftCardTotals, *pTGiftCardTotals;

そして、これは私がC#で行った方法です:

[DllImport("batch.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Auto)]
  public static extern int BatchTotal_Transactions(int transType, ref giftCardReqBatchTotal req, ref giftCardRespBatchTotal resp, IntPtr com);


    [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
    public struct _tagGiftCardReqBatchTotal
    {
        [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 9)]
        public string Password;

        [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 9)]
        public string OperatorID;

        [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 14)]
        public string BatchNum;

        [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 11)]
        public string StartDate;

        [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 11)]
        public string EndDate;

        public byte Type;
    }

    [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
    public struct _tagGiftCardRespBatchTotal
    {
        public byte Result;

        [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 17)]
        public string TerminalId;

        public byte DispMsgControl;

        [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 256)]
        public string DispMsg;

        [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 41)]
        public string Display;

        [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 11)]
        public string Date;

        [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 9)]
        public string Time;

        [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 4)]
        public string RespCode;

        [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 14)]
        public string BatchNum;

        public byte ErrorFlag;

        public byte CustLang;

        public byte UserLang;

        [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 17)]
        public string OpenDate;

        [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 17)]
        public string ClosedDate;

        [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 11)]
        public string StartDate;

        [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 11)]
        public string EndDate;

        public byte BatchStatus;

        int CardTypeNum;

        [MarshalAs(UnmanagedType.Struct, SizeConst = 1024)]
        public _tagGiftCardTotals GctHost;

        [MarshalAs(UnmanagedType.Struct, SizeConst = 1024)]
        public _tagGiftCardTotals GctTRS;
    }

    [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
    public struct _tagGiftCardTotals
    {
        public UInt16 CardCode;

        public UInt16 PurchaseNum;

        public int PurchaseTotal;

        public UInt16 RefundNum;

        public int RefundTotal;

        public UInt16 RedemptionNum;

        public int RedemptionTotal;

        public UInt16 CorrectionNum;

        public int CorrectionTotal;

        public int PurchaseBenefitTotal;

        public int RefundBenefitTotal;

        public int RedemptionBenefitTotal;
    }
4

1 に答える 1