高分:如何把Socket作为参数传递?分不够再加!!!!

wixwiz 2003-10-19 03:35:27
下面是在C#中声明的结构
using System.Net.Sockets ;

public struct conn_desc //完成
{
public Socket sock;
public long seq;
public int status;
public char act_flag;
}
下面是函数声明
[DllImport("api.dll")] public unsafe static extern int cmpp_connect_to_ismg(string host, short port, conn_desc conn);
api.dll是要调用的外部文件,不能改动

conn_desc conn原型如下:
struct conn_desc{
SOCKET sock;
int seq;
int status;
char act_flag;
};

上面的conn_desc 是仿造这个写的

问题:当我如下方式调用函数时
conn_desc conn=new conn_desc();
cmpp_connect_to_ismg("211.*.*.*",5632,conn);
出现如下错误:
无法封送类型 conn_desc 的字段 sock:该字段的类型定义没有布局信息。
说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。

异常详细信息: System.TypeLoadException: 无法封送类型 conn_desc 的字段 sock:该字段的类型定义没有布局信息。

源错误:


行 161: conn_desc conn=new conn_desc();
行 162: conn.seq=0;
行 163: cmpp_connect_to_ismg("211.*.*.*",5632,conn);
行 164:
行 165: }

以上程序在C++中调用是没有任何的。
请高手指点。急啊。拜托了!!
...全文
74 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
wixwiz 2003-10-19
  • 打赏
  • 举报
回复
我试过了,还是不行。哎
ehuar 2003-10-19
  • 打赏
  • 举报
回复
Socket是引用类型,可以直接传递
rgbcn 2003-10-19
  • 打赏
  • 举报
回复
conn_desc conn=new conn_desc();
cmpp_connect_to_ismg("211.*.*.*",5632,conn);

不是这样调用的。

你定一个方法 返回类型为conn_desc

public conn_desc GetSecurityInfo()
{
return SOCKET

}
cmpp_connect_to_ismg("211.*.*.*",5632,conn);
wixwiz 2003-10-19
  • 打赏
  • 举报
回复
没有人回答吗
rgbcn 2003-10-19
  • 打赏
  • 举报
回复
gz
维她奶 2003-10-19
  • 打赏
  • 举报
回复
up

110,500

社区成员

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

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

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