求救,C# 调用C编写的dll问题

ctjtn 2013-06-13 08:14:54
C原型:
typedef enum _SUPPORT_LAYER
{
HDLC = 0x01,
TCPIP,
UDPIP
}SUPPORT_LAYER;

typedef union _ADDR
{
struct
{
unsigned int ServerLowerAddr : 14; //服务器低地址
unsigned int ServerUpperAddr : 14; //服务器高地址
unsigned int res : 4;
unsigned char ClientAddr;
unsigned char ServerAddrLen;
}HDLC_ADDR1;

struct
{
unsigned int ServerAddr : 28;
unsigned int res : 4;
unsigned char ClientAddr;
unsigned char ServerAddrLen;
}HDLC_ADDR2;

struct
{
unsigned int Client_TCP_Port;
unsigned int Server_TCP_Port;
unsigned char Client_IP_Addr[4];
unsigned char Server_IP_Addr[4];
}TCPIP_ADDR;

struct
{
unsigned int Client_wPort;
unsigned int Server_wPort;
unsigned int Client_UDP_Port;
unsigned int Server_UDP_Port;
unsigned char Client_IP_Addr[4];
unsigned char Server_IP_Addr[4];
}UDPIP_ADDR;
}ADDR;

int ProcessServicePrimitive(unsigned char **OUTData, unsigned int &OUTDataLen,SUPPORT_LAYER SupportLayerType, ADDR Addr,const unsigned char *Xml, unsigned int XmlLen);
请问如何用C#调用ProcessServicePrimitive参数?
...全文
110 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
ctjtn 2013-06-17
  • 打赏
  • 举报
回复
现在解决了,3楼说的是正确的
ctjtn 2013-06-15
  • 打赏
  • 举报
回复
额。。。没人理啊
owennol 2013-06-15
  • 打赏
  • 举报
回复
Union应该是共享地址的,大小为最大的结构体所占的大小 [StructLayout(LayoutKind.Explicit,Size=24)] public struct ADDR { [FieldOffset(0)] public HDLC_ADDR1 a; [FieldOffset(0)] public HDLC_ADDR2 b; [FieldOffset(0)] public TCPIP_ADDR c; [FieldOffset(0)] public UDPIP_ADDR d; }
ctjtn 2013-06-13
  • 打赏
  • 举报
回复
public enum SUPPORT_LAYER { HDLC = 0x01, TCPIP, UDPIP } [StructLayout(LayoutKind.Sequential)] public struct HDLC_ADDR1 { public uint ServerLowerAddr; public uint ServerUpperAddr; public uint res; public char ClientAddr; public char ServerAddrLen; }; [StructLayout(LayoutKind.Sequential)] public struct HDLC_ADDR2 { public uint ServerAddr; public uint res; public char ClientAddr; public char ServerAddrLen; } [StructLayout(LayoutKind.Sequential)] public struct TCPIP_ADDR { public uint Client_TCP_Port; public uint Server_TCP_Port; public char [] Client_IP_Addr; public char [] Server_IP_Addr; } [StructLayout(LayoutKind.Sequential)] public struct UDPIP_ADDR { public uint Client_wPort; public uint Server_wPort; public uint Client_UDP_Port; public uint Server_UDP_Port; public char [] Client_IP_Addr; public char [] Server_IP_Addr; } [StructLayout(LayoutKind.Explicit,Size=500)] public struct ADDR { [FieldOffset(0)] public HDLC_ADDR1 a; [FieldOffset(50)] public HDLC_ADDR2 b; [FieldOffset(180)] public TCPIP_ADDR c; [FieldOffset(300)] public UDPIP_ADDR d; } [DllImport("pro_C62056.dll")] public static extern int ProcessServicePrimitive( ref string str, ref UInt32 len, SUPPORT_LAYER SupportLayerType, ADDR Addr, string strxml, int len1); 我这样调用老是提示外部组件异常

110,533

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧