vc++传结构体到C#中,为啥C#中的值 老是一样的!!

li_ming_ming 2012-05-29 02:22:59
vc+++
struct Point
{
int x,y;
int _x,_y;
int width,height;
int frameSum;
float length;
char pictureName[50];
bool Success;
int order;
float area;
int X,Y;
} ;



C#
[StructLayout(LayoutKind.Sequential)]
public struct Point
{
int star_x,star_y;
int end_x,end_y;
int width,height;
int frameSum;
float length;

[MarshalAs(UnmanagedType.ByValArray, SizeConst = 50)] // 声明一个字符数组,大小为50
char[] pictureName;

bool Success;
int order;
float area;
int X,Y;
};

VC++
char recvstr[sizeof(Point)];
memcpy(recvstr,&defectpoint,sizeof(Point));
send(sockClient,recvstr,sizeof(Point),0);

C#
buffer = new byte[1024];
ns.Read(buffer, 0, buffer.Length);
Pointdefepoint = (Point)BytesToStruct(buffer, typeof(Point));


帮帮忙 在线等啊。
...全文
73 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
qldsrx 2012-05-29
  • 打赏
  • 举报
回复
你把传值调用的代码贴出来啊。
li_ming_ming 2012-05-29
  • 打赏
  • 举报
回复
你有QQ吗 我加一下 我还有问题想请教

就是 传过来的值总是第一次传的那些值  

li_ming_ming 2012-05-29
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 的回复:]

[MarshalAs(UnmanagedType.ByValArray, SizeConst = 50)] // 声明一个字节数组,大小为50
byte[] pictureName;
或者
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 50)] // 声明一个字符串,大小为50
string pictureName;

C++的c……
[/Quote]

嗯 刚才查了下C#中char是2位 我改成byte试试 谢谢
qldsrx 2012-05-29
  • 打赏
  • 举报
回复
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 50)] // 声明一个字节数组,大小为50
byte[] pictureName;
或者
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 50)] // 声明一个字符串,大小为50
string pictureName;

C++的char一个字节,等于C#的byte,C#的char两个字节,因此你就不能那么定义。
ONE-PIECE 2012-05-29
  • 打赏
  • 举报
回复
http://topic.csdn.net/u/20120528/17/8fc50d63-d913-4187-9354-da7310ec8efa.html
回复下!!!!!!!!!!

111,126

社区成员

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

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

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