gpt4 book ai didi

c# - 另一个 PInvoke - 错误消息显示未找到源?

转载 作者:行者123 更新时间:2023-11-30 17:46:24 26 4
gpt4 key购买 nike

当我在 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;
}

最佳答案

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

Specified module could not be found.

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

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

关于c# - 另一个 PInvoke - 错误消息显示未找到源?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19306283/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com