C#调用C++的Dll方法,const char Content[]在C#中采用什么类型?? 20
C++方法:intReqComm(DWORDDestUser,DWORDContentLen,constcharContent[],BOOLifHaste=FALSE,i...
C++方法:
int ReqComm(DWORD DestUser, DWORD ContentLen,const char Content[], BOOL ifHaste=FALSE,int ifBCD=1);
C#声明方法:
[DllImport("BDProtocol.dll", EntryPoint = "ReqComm", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Cdecl)]
public static extern int ReqComm(UInt32 DestUser, UInt32 ContentLen,
[In][MarshalAsAttribute(UnmanagedType.LPArray, ArraySubType=UnmanagedType.LPStr)] byte[] content, Int32 ifHaste, int ifBCD);
C#调用:
byte[] tt = Encoding.ASCII.GetBytes("123");
UInt32 length = Convert.ToUInt32(tt.Length);
textBox1.Text = ReqComm(Convert.ToUInt32(2096135), length, tt, 00, 0).ToString();
函数返回值表
enum {
SUCCESS = 0, 操作成功
FAILURE, 操作失败
DLL_NOTINITIAL, 动态库未初始化
DLL_COMPORTUSED, 串口被占用
DLL_PARAMERR, 参数输入错误
DLL_NOIDINFO, 未获得本机信息
DLL_CONTENTTOOLONG 通信过长,超过最大长度
};
目前调用不保存,方法调用后有返回值,但返回值为5,老是不成功,请高手现身帮帮忙吧 展开
int ReqComm(DWORD DestUser, DWORD ContentLen,const char Content[], BOOL ifHaste=FALSE,int ifBCD=1);
C#声明方法:
[DllImport("BDProtocol.dll", EntryPoint = "ReqComm", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Cdecl)]
public static extern int ReqComm(UInt32 DestUser, UInt32 ContentLen,
[In][MarshalAsAttribute(UnmanagedType.LPArray, ArraySubType=UnmanagedType.LPStr)] byte[] content, Int32 ifHaste, int ifBCD);
C#调用:
byte[] tt = Encoding.ASCII.GetBytes("123");
UInt32 length = Convert.ToUInt32(tt.Length);
textBox1.Text = ReqComm(Convert.ToUInt32(2096135), length, tt, 00, 0).ToString();
函数返回值表
enum {
SUCCESS = 0, 操作成功
FAILURE, 操作失败
DLL_NOTINITIAL, 动态库未初始化
DLL_COMPORTUSED, 串口被占用
DLL_PARAMERR, 参数输入错误
DLL_NOIDINFO, 未获得本机信息
DLL_CONTENTTOOLONG 通信过长,超过最大长度
};
目前调用不保存,方法调用后有返回值,但返回值为5,老是不成功,请高手现身帮帮忙吧 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询