天生小身板 2015-08-27 07:29 采纳率: 50%
浏览 1918
已采纳

c# c++ 之间网口通信 结构体 转换

下面是 C++的结构体 转换成 C# 怎么写 真心不懂 请附上值 把 IP 端口那些 都填上
/*Structure used in select() call,taken from the BSD file sys/tim.h.*/
struct timeval{
long tv_sec; /*seconde*/
long tv_usec; /*and microseconds*/
}

/*Socket address,internet style.*/
struct sockaddr_in{
short sin_family;
u_short sin_port;
char sin_zero[8];
}

/*The new type to be used in all. instances which refer to sockets*/
typedef UINT_PTR SOCKET;

真心不懂 请尽量详细点

int _stdcall ConnectNetPort(SOCKET *lpSocket,//传入已分配套接字的指针
SOCKADDR_IN * pPrinterAddr, //打印机的地址
timeval *lpTimeout); //超时
功能说明:
调用该函数将会连接打印机。成功返回1,失败返回值见下:
-1:创建套接字失败。
-2:设¦为非阻塞模式失败。
-3:连接超时。
-4:Select错误

这个是一个网口热敏打印机的

  • 写回答

3条回答 默认 最新

  • threenewbee 2015-08-27 07:48
    关注
      [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
    struct timeval{
    int tv_sec; /*seconde*/
    int tv_usec; /*and microseconds*/
    }
    /*Socket address,internet style.*/
     [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
    struct sockaddr_in{
    short sin_family;
    ushort sin_port;
    [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 8)]
    string sin_zero[8];
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 微信公众号自制会员卡没有收款渠道啊
  • ¥15 stable diffusion
  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘
  • ¥15 perl MISA分析p3_in脚本出错
  • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
  • ¥15 ubuntu虚拟机打包apk错误
  • ¥199 rust编程架构设计的方案 有偿