0

我在 c# 中构建的结构在针对该函数运行时没有给我一条错误消息,告诉我结构有问题。它说找不到源文件。同样,由于缺乏文档,我对这个 DLL b/c 了解不多。但我仍然认为这是因为我设置了错误的结构。很可能我在想第三个结构,它在结构中引用一个结构。我希望对我所做的工作有一些反馈。感谢您的帮助。

这是 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

0

您确定错误不是以下内容:

找不到指定的模块。

如果这是错误,那是因为找不到 dll。确保 dll 在您的路径中:

http://msdn.microsoft.com/en-us/library/system.runtime.interopservices.dllimportattribute.value.aspx

于 2013-10-10T23:12:54.623 回答