紧急:Unix / Windows Struct转换问题 [英] URGENT: Unix/Windows Struct cast problem
问题描述
Follwing结构:
[StructLayout(LayoutKind.Sequential,Pack = 1,CharSet = CharSet.Ansi)]
public struct TpSomeMsgRep
{
public uint SomeId;
[MarshalAs(UnmanagedType.ByValArray,SizeConst = 2) ]
public Byte [] notinuse1;
[MarshalAs(UnmanagedType.ByValArray,SizeConst = 674)]
>
public Byte [] theMainPart;
}
用于从缓冲区转换,由TCP从C ++程序收到,像这样:
oMsgRes =(mm.TpSomeMsgRep)SomeBuffer;
这对Unix服务器来说很好用。一旦转移到Windows我就无法投射到结构。
请帮助帮助帮助!
-
Tamir Khason
您想要dot.NET吗?只需询问:
"请, www.dotnet.us
Follwing the struct:
[StructLayout(LayoutKind.Sequential, Pack=1, CharSet=CharSet.Ansi)]
public struct TpSomeMsgRep
{
public uint SomeId;
[MarshalAs(UnmanagedType.ByValArray, SizeConst=2)]
public Byte[] notinuse1;
[MarshalAs(UnmanagedType.ByValArray, SizeConst=674)]
public Byte[] theMainPart;
}
This used to cast from buffer, recieved by TCP from C++ Program, like this:
oMsgRes= (mm.TpSomeMsgRep )SomeBuffer;
This work fine with Unix server. once transfer to Windows I can not cast to
the structure.
PLEASE HELP HELP HELP!
--
Tamir Khason
You want dot.NET? Just ask:
"Please, www.dotnet.us "
推荐答案
如果您能提供代码如何收到
包,那将会很棒在C#所以我们可以看到如何帮助你。
-
cody
免费软件工具,游戏和幽默
http://www.deutronium.de.vu | | http://www.deutronium.tk
" Tamir Khason" < TA ********** @ tcon-NOSPAM.co.il> schrieb im Newsbeitrag
新闻:OK ************** @ TK2MSFTNGP09.phx.gbl ...
Would be great if you could provide the code how you are receiving the
packets in C# so we can see how to help you.
--
cody
Freeware Tools, Games and Humour
http://www.deutronium.de.vu || http://www.deutronium.tk
"Tamir Khason" <ta**********@tcon-NOSPAM.co.il> schrieb im Newsbeitrag
news:OK**************@TK2MSFTNGP09.phx.gbl...
Follwing结构:< br> [StructLayout(LayoutKind.Sequential,Pack = 1,CharSet = CharSet.Ansi)]
公共结构TpSomeMsgRep
公众uint SomeId;
[MarshalAs(UnmanagedType.ByValArray,SizeConst = 2)]
public Byte [] notinuse1;
[MarshalAs(UnmanagedType。 ByValArray,SizeConst = 674)]
公共字节[] theMainPart;
}
这用于从缓冲区转换,由TCP从C ++收到程序,比如
这个:
oMsgRes =(mm.TpSomeMsgRep)SomeBuffer;
这对Unix服务器来说很好用。一旦转移到Windows,我就无法向该结构投入
。
请帮助帮助!
-
Tamir Khason
你想要dot.NET吗?只需询问:
请, www.dotnet.us "
Follwing the struct:
[StructLayout(LayoutKind.Sequential, Pack=1, CharSet=CharSet.Ansi)]
public struct TpSomeMsgRep
{
public uint SomeId;
[MarshalAs(UnmanagedType.ByValArray, SizeConst=2)]
public Byte[] notinuse1;
[MarshalAs(UnmanagedType.ByValArray, SizeConst=674)]
public Byte[] theMainPart;
}
This used to cast from buffer, recieved by TCP from C++ Program, like this:
oMsgRes= (mm.TpSomeMsgRep )SomeBuffer;
This work fine with Unix server. once transfer to Windows I can not cast to the structure.
PLEASE HELP HELP HELP!
--
Tamir Khason
You want dot.NET? Just ask:
"Please, www.dotnet.us "
代码看起来像普通的异步TCP客户端
-
Tamir Khason
您想要dot.NET吗?只需询问:
"请, www.dotnet.us
cody" <无**************** @ gmx.net>在消息中写道
新闻:O2 ************** @ TK2MSFTNGP10.phx.gbl ...
The code is looking like regular Async TCP Client
--
Tamir Khason
You want dot.NET? Just ask:
"Please, www.dotnet.us "
"cody" <no****************@gmx.net> wrote in message
news:O2**************@TK2MSFTNGP10.phx.gbl...
如果你会很棒可以提供代码如何在C#中接收
包,这样我们就可以看到如何帮助你。
-
cody
免费软件工具,游戏和幽默
http://www.deutronium.de.vu || http://www.deutronium.tk
Tamir Khason < TA ********** @ tcon-NOSPAM.co.il> schrieb im Newsbeitrag
新闻:OK ************** @ TK2MSFTNGP09.phx.gbl ...
Would be great if you could provide the code how you are receiving the
packets in C# so we can see how to help you.
--
cody
Freeware Tools, Games and Humour
http://www.deutronium.de.vu || http://www.deutronium.tk
"Tamir Khason" <ta**********@tcon-NOSPAM.co.il> schrieb im Newsbeitrag
news:OK**************@TK2MSFTNGP09.phx.gbl...
Follwing结构:
[ StructLayout(LayoutKind.Sequential,Pack = 1,CharSet = CharSet.Ansi)]
public struct TpSomeMsgRep
公共uint SomeId;
[MarshalAs(UnmanagedType.ByValArray,SizeConst = 2)]
public Byte [] notinuse1;
[MarshalAs(UnmanagedType.ByValArray,SizeConst = 674)]
公共字节[] theMainPart;
这用于从缓冲区转换,由TCP从C ++程序接收,如
Follwing the struct:
[StructLayout(LayoutKind.Sequential, Pack=1, CharSet=CharSet.Ansi)]
public struct TpSomeMsgRep
{
public uint SomeId;
[MarshalAs(UnmanagedType.ByValArray, SizeConst=2)]
public Byte[] notinuse1;
[MarshalAs(UnmanagedType.ByValArray, SizeConst=674)]
public Byte[] theMainPart;
}
This used to cast from buffer, recieved by TCP from C++ Program, like
这个:
oMsgRes =(mm.TpSomeMsgRep)SomeBuffer;
这对Unix服务器来说很好用。一旦转移到Windows我无法将
oMsgRes= (mm.TpSomeMsgRep )SomeBuffer;
This work fine with Unix server. once transfer to Windows I can not cast
转换为
结构。
请帮助帮助!
- -
Tamir Khason
你想要dot.NET吗?只需询问:
请, www.dotnet.us "
the structure.
PLEASE HELP HELP HELP!
--
Tamir Khason
You want dot.NET? Just ask:
"Please, www.dotnet.us "
" Tamir Khason" < TA ********** @ tcon-NOSPAM.co.il>在消息中写道
news:OK ************** @ TK2MSFTNGP09.phx.gbl ...
Hi,
"Tamir Khason" <ta**********@tcon-NOSPAM.co.il> wrote in message
news:OK**************@TK2MSFTNGP09.phx.gbl...
Follwing结构:< br> [StructLayout(LayoutKind.Sequential,Pack = 1,CharSet = CharSet.Ansi)]
公共结构TpSomeMsgRep
公众uint SomeId;
[MarshalAs(UnmanagedType.ByValArray,SizeConst = 2)]
public Byte [] notinuse1;
[MarshalAs(UnmanagedType。 ByValArray,SizeConst = 674)]
公共字节[] theMainPart;
}
这用于从缓冲区转换,由TCP从C ++收到程序,比如
这个:
oMsgRes =(mm.TpSomeMsgRep)SomeBuffer;
这对Unix服务器来说很好用。一旦转移到Windows我就无法将
投射到结构中。
如果要将字节数组转换为
结构,你必须使用编组功能:
byte [] buf = *收到*;
GCHandle h = GCHandle.Alloc(buf,GCHandleType.Pinned);
TpSomeMsgRep rep =( TpSomeMsgRep)Marshal.PtrToStruct(h.AddrOfPinnedOb ject(),
typeof(TpSomeMsgRep));
h.Free();
/ /使用代表
如果您需要别的东西,请更具体。
HTH,
问候
请帮助帮助!
-
Tamir Khason
你想要dot.NET吗?只需询问:
请, www.dotnet.us "
Follwing the struct:
[StructLayout(LayoutKind.Sequential, Pack=1, CharSet=CharSet.Ansi)]
public struct TpSomeMsgRep
{
public uint SomeId;
[MarshalAs(UnmanagedType.ByValArray, SizeConst=2)]
public Byte[] notinuse1;
[MarshalAs(UnmanagedType.ByValArray, SizeConst=674)]
public Byte[] theMainPart;
}
This used to cast from buffer, recieved by TCP from C++ Program, like this:
oMsgRes= (mm.TpSomeMsgRep )SomeBuffer;
This work fine with Unix server. once transfer to Windows I can not cast to the structure.
What and how are you casting, if you want to cast a byte array to your
struct, you must use marshalling functionality:
byte [] buf = * received * ;
GCHandle h = GCHandle.Alloc( buf, GCHandleType.Pinned );
TpSomeMsgRep rep = (TpSomeMsgRep)Marshal.PtrToStruct(h.AddrOfPinnedOb ject(),
typeof(TpSomeMsgRep));
h.Free();
// use rep
If you need something else, be more specific.
HTH,
greetings
PLEASE HELP HELP HELP!
--
Tamir Khason
You want dot.NET? Just ask:
"Please, www.dotnet.us "
这篇关于紧急:Unix / Windows Struct转换问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!