By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
425,710 Members | 1,626 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 425,710 IT Pros & Developers. It's quick & easy.

URGENT: Unix/Windows Struct cast problem

P: n/a
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 "

Nov 16 '05 #1
Share this Question
Share on Google+
28 Replies


P: n/a
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 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 "

Nov 16 '05 #2

P: n/a
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...
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 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 "


Nov 16 '05 #3

P: n/a
Hi,

"Tamir Khason" <ta**********@tcon-NOSPAM.co.il> wrote in message
news:OK**************@TK2MSFTNGP09.phx.gbl...
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 "

Nov 16 '05 #4

P: n/a
I'm doing this.
The question is what can be different between the packets between Unix and
Windows packets...

--
Tamir Khason
You want dot.NET? Just ask:
"Please, www.dotnet.us "
"BMermuys" <so*****@someone.com> wrote in message
news:kb**********************@phobos.telenet-ops.be...
Hi,

"Tamir Khason" <ta**********@tcon-NOSPAM.co.il> wrote in message
news:OK**************@TK2MSFTNGP09.phx.gbl...
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 "


Nov 16 '05 #5

P: n/a

"Tamir Khason" <ta**********@tcon-NOSPAM.co.il> wrote in message
news:ug**************@TK2MSFTNGP10.phx.gbl...
I'm doing this.
The question is what can be different between the packets between Unix and
Windows packets...
You're are still not very clear. Is this server written in c++ compiled for
both linux/windows?

I don't think struct differ from one platform to another. Struct alignment
may cause different struct layout's but that is compiler dependent not
platform.

What's exactly is the problem you have ? Does PtrToStruct throw ?
Unexpected data ??

greetings


--
Tamir Khason
You want dot.NET? Just ask:
"Please, www.dotnet.us "
"BMermuys" <so*****@someone.com> wrote in message
news:kb**********************@phobos.telenet-ops.be...
Hi,

"Tamir Khason" <ta**********@tcon-NOSPAM.co.il> wrote in message
news:OK**************@TK2MSFTNGP09.phx.gbl...
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 "



Nov 16 '05 #6

P: n/a
Struct alignment
may cause different struct layout's but that is compiler dependent not
platform. Yes, both servers sources were compiled with alignment 4 both for unix (sun)
and windows
What's exactly is the problem you have ? Does PtrToStruct throw ?
Unexpected data ?? No, PtrToStruct works well, but in cast with
(MyStruct)ObjectSerializedFromBinaryStream failed.


--
Tamir Khason
You want dot.NET? Just ask:
"Please, www.dotnet.us "
"BMermuys" <so*****@someone.com> wrote in message
news:vB**********************@phobos.telenet-ops.be...
"Tamir Khason" <ta**********@tcon-NOSPAM.co.il> wrote in message
news:ug**************@TK2MSFTNGP10.phx.gbl...
I'm doing this.
The question is what can be different between the packets between Unix and
Windows packets...
You're are still not very clear. Is this server written in c++ compiled

for both linux/windows?

I don't think struct differ from one platform to another. Struct alignment may cause different struct layout's but that is compiler dependent not
platform.

What's exactly is the problem you have ? Does PtrToStruct throw ?
Unexpected data ??

greetings


--
Tamir Khason
You want dot.NET? Just ask:
"Please, www.dotnet.us "
"BMermuys" <so*****@someone.com> wrote in message
news:kb**********************@phobos.telenet-ops.be...
Hi,

"Tamir Khason" <ta**********@tcon-NOSPAM.co.il> wrote in message
news:OK**************@TK2MSFTNGP09.phx.gbl...
> 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 "
>
>
>



Nov 16 '05 #7

P: n/a
What is ObjectSerializedFromBinaryStream? It seems not to be part of the
Framework.
If you want that we help you you have to provive more information for
example show your code that receives the packets.

--
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:#v**************@tk2msftngp13.phx.gbl...
Struct alignment
may cause different struct layout's but that is compiler dependent not
platform. Yes, both servers sources were compiled with alignment 4 both for unix

(sun) and windows
What's exactly is the problem you have ? Does PtrToStruct throw ?
Unexpected data ??

No, PtrToStruct works well, but in cast with
(MyStruct)ObjectSerializedFromBinaryStream failed.


--
Tamir Khason
You want dot.NET? Just ask:
"Please, www.dotnet.us "
"BMermuys" <so*****@someone.com> wrote in message
news:vB**********************@phobos.telenet-ops.be...

"Tamir Khason" <ta**********@tcon-NOSPAM.co.il> wrote in message
news:ug**************@TK2MSFTNGP10.phx.gbl...
I'm doing this.
The question is what can be different between the packets between Unix and Windows packets...


You're are still not very clear. Is this server written in c++ compiled

for
both linux/windows?

I don't think struct differ from one platform to another. Struct

alignment
may cause different struct layout's but that is compiler dependent not
platform.

What's exactly is the problem you have ? Does PtrToStruct throw ?
Unexpected data ??

greetings


--
Tamir Khason
You want dot.NET? Just ask:
"Please, www.dotnet.us "
"BMermuys" <so*****@someone.com> wrote in message
news:kb**********************@phobos.telenet-ops.be...
> Hi,
>
> "Tamir Khason" <ta**********@tcon-NOSPAM.co.il> wrote in message
> news:OK**************@TK2MSFTNGP09.phx.gbl...
> > 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 "
> >
> >
> >
>
>



Nov 16 '05 #8

P: n/a
This just name of variable to explain where ti tooked from :)

Anyway there is no way to provide full source it a lot of classes with
relations etc.
The point is that there are diferences between unix and windows TCP or
binary stream....
advice

"cody" <no****************@gmx.net> wrote in message
news:OW**************@TK2MSFTNGP12.phx.gbl...
What is ObjectSerializedFromBinaryStream? It seems not to be part of the
Framework.
If you want that we help you you have to provive more information for
example show your code that receives the packets.

--
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:#v**************@tk2msftngp13.phx.gbl...
Struct alignment
may cause different struct layout's but that is compiler dependent not
platform.

Yes, both servers sources were compiled with alignment 4 both for unix

(sun)
and windows
What's exactly is the problem you have ? Does PtrToStruct throw ?
Unexpected data ??

No, PtrToStruct works well, but in cast with
(MyStruct)ObjectSerializedFromBinaryStream failed.


--
Tamir Khason
You want dot.NET? Just ask:
"Please, www.dotnet.us "
"BMermuys" <so*****@someone.com> wrote in message
news:vB**********************@phobos.telenet-ops.be...

"Tamir Khason" <ta**********@tcon-NOSPAM.co.il> wrote in message
news:ug**************@TK2MSFTNGP10.phx.gbl...
> I'm doing this.
> The question is what can be different between the packets between
Unix
and
> Windows packets...

You're are still not very clear. Is this server written in c++
compiled for
both linux/windows?

I don't think struct differ from one platform to another. Struct

alignment
may cause different struct layout's but that is compiler dependent not
platform.

What's exactly is the problem you have ? Does PtrToStruct throw ?
Unexpected data ??

greetings
>
> --
> Tamir Khason
> You want dot.NET? Just ask:
> "Please, www.dotnet.us "
>
>
> "BMermuys" <so*****@someone.com> wrote in message
> news:kb**********************@phobos.telenet-ops.be...
> > Hi,
> >
> > "Tamir Khason" <ta**********@tcon-NOSPAM.co.il> wrote in message
> > news:OK**************@TK2MSFTNGP09.phx.gbl...
> > > 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 "
> > >
> > >
> > >
> >
> >
>
>



Nov 16 '05 #9

P: n/a
> Anyway there is no way to provide full source it a lot of classes with
relations etc.
The point is that there are diferences between unix and windows TCP or
binary stream....

I do not believe that. The bytes can be read from the stream the same way
you put them in.
The marshaller will take care that the byte order (big endian/little endian)
in your struct's variables will be ok.

Remember that you have to pass the correct type to PtrToStruct, otherwise
itt will output the wrong type.

--
cody

Freeware Tools, Games and Humour
http://www.deutronium.de.vu || http://www.deutronium.tk
Nov 16 '05 #10

P: n/a
Hi,

"Tamir Khason" <ta**********@tcon-NOSPAM.co.il> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
Struct alignment
may cause different struct layout's but that is compiler dependent not
platform. Yes, both servers sources were compiled with alignment 4 both for unix

(sun) and windows


Then why are you using Pack=1 on the struct ?

Greetings

What's exactly is the problem you have ? Does PtrToStruct throw ?
Unexpected data ??

No, PtrToStruct works well, but in cast with
(MyStruct)ObjectSerializedFromBinaryStream failed.


--
Tamir Khason
You want dot.NET? Just ask:
"Please, www.dotnet.us "
"BMermuys" <so*****@someone.com> wrote in message
news:vB**********************@phobos.telenet-ops.be...

"Tamir Khason" <ta**********@tcon-NOSPAM.co.il> wrote in message
news:ug**************@TK2MSFTNGP10.phx.gbl...
I'm doing this.
The question is what can be different between the packets between Unix and Windows packets...


You're are still not very clear. Is this server written in c++ compiled

for
both linux/windows?

I don't think struct differ from one platform to another. Struct

alignment
may cause different struct layout's but that is compiler dependent not
platform.

What's exactly is the problem you have ? Does PtrToStruct throw ?
Unexpected data ??

greetings


--
Tamir Khason
You want dot.NET? Just ask:
"Please, www.dotnet.us "
"BMermuys" <so*****@someone.com> wrote in message
news:kb**********************@phobos.telenet-ops.be...
> Hi,
>
> "Tamir Khason" <ta**********@tcon-NOSPAM.co.il> wrote in message
> news:OK**************@TK2MSFTNGP09.phx.gbl...
> > 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 "
> >
> >
> >
>
>



Nov 16 '05 #11

P: n/a
So what I have to use?

--
Tamir Khason
You want dot.NET? Just ask:
"Please, www.dotnet.us "

"BMermuys" <so*****@someone.com> wrote in message
news:Jl**********************@phobos.telenet-ops.be...
Hi,

"Tamir Khason" <ta**********@tcon-NOSPAM.co.il> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
Struct alignment
may cause different struct layout's but that is compiler dependent not
platform.

Yes, both servers sources were compiled with alignment 4 both for unix

(sun)
and windows


Then why are you using Pack=1 on the struct ?

Greetings

What's exactly is the problem you have ? Does PtrToStruct throw ?
Unexpected data ??

No, PtrToStruct works well, but in cast with
(MyStruct)ObjectSerializedFromBinaryStream failed.


--
Tamir Khason
You want dot.NET? Just ask:
"Please, www.dotnet.us "
"BMermuys" <so*****@someone.com> wrote in message
news:vB**********************@phobos.telenet-ops.be...

"Tamir Khason" <ta**********@tcon-NOSPAM.co.il> wrote in message
news:ug**************@TK2MSFTNGP10.phx.gbl...
> I'm doing this.
> The question is what can be different between the packets between
Unix
and
> Windows packets...

You're are still not very clear. Is this server written in c++
compiled for
both linux/windows?

I don't think struct differ from one platform to another. Struct

alignment
may cause different struct layout's but that is compiler dependent not
platform.

What's exactly is the problem you have ? Does PtrToStruct throw ?
Unexpected data ??

greetings
>
> --
> Tamir Khason
> You want dot.NET? Just ask:
> "Please, www.dotnet.us "
>
>
> "BMermuys" <so*****@someone.com> wrote in message
> news:kb**********************@phobos.telenet-ops.be...
> > Hi,
> >
> > "Tamir Khason" <ta**********@tcon-NOSPAM.co.il> wrote in message
> > news:OK**************@TK2MSFTNGP09.phx.gbl...
> > > 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 "
> > >
> > >
> > >
> >
> >
>
>



Nov 16 '05 #12

P: n/a
You should use the same pack that was used to generate the original struct.
If you are not sure, compare their sizes (your struct and the receiced
packet).
If it is the same your pack size is correct.

if the cast from ObjectSerializedFromBinaryStream failed try to display the
type of the generated object:

Console.WriteLine(ObjectSerializedFromBinaryStream ().GetType());

maybe that can give you the idea what got wrong.

However if you would post the piece of code you are using for receiving the
packets you have much bigger chances somebody here can solve your problem.

--
cody

Freeware Tools, Games and Humour
http://www.deutronium.de.vu || http://www.deutronium.tk
Nov 16 '05 #13

P: n/a
The problem is WHAT I'M passing in.
I revieve the stream from C++ server.
When it was in UNIX enviroment - everything worked ok, but once they
treanfer to Windows the problem begun. There are same structures, but as far
as I understand , not the same stream - thet's the single explanation I can
think about...

--
Tamir Khason
You want dot.NET? Just ask:
"Please, www.dotnet.us "

"cody" <no****************@gmx.net> wrote in message
news:uE**************@TK2MSFTNGP10.phx.gbl...
Anyway there is no way to provide full source it a lot of classes with
relations etc.
The point is that there are diferences between unix and windows TCP or
binary stream....

I do not believe that. The bytes can be read from the stream the same way
you put them in.
The marshaller will take care that the byte order (big endian/little

endian) in your struct's variables will be ok.

Remember that you have to pass the correct type to PtrToStruct, otherwise
itt will output the wrong type.

--
cody

Freeware Tools, Games and Humour
http://www.deutronium.de.vu || http://www.deutronium.tk

Nov 16 '05 #14

P: n/a
Hi,

"Tamir Khason" <ta**********@tcon-NOSPAM.co.il> wrote in message
news:uu**************@TK2MSFTNGP10.phx.gbl...
The problem is WHAT I'M passing in.
I revieve the stream from C++ server.
When it was in UNIX enviroment - everything worked ok, but once they
treanfer to Windows the problem begun. There are same structures, but as far as I understand , not the same stream - thet's the single explanation I can think about...
So, if you only see this problem when the server is on Windows and not on
Linux, you can agree that the problem is with the server and not the client.

Can't you post some code, how do you transmit this struct in c++, do you
cast the struct* to a byte* ?

I still don't quite understand what the problem is you're having if
PtrToStruct works.

HTH,
greetings


--
Tamir Khason
You want dot.NET? Just ask:
"Please, www.dotnet.us "

"cody" <no****************@gmx.net> wrote in message
news:uE**************@TK2MSFTNGP10.phx.gbl...
Anyway there is no way to provide full source it a lot of classes with
relations etc.
The point is that there are diferences between unix and windows TCP or
binary stream....

I do not believe that. The bytes can be read from the stream the same way you put them in.
The marshaller will take care that the byte order (big endian/little

endian)
in your struct's variables will be ok.

Remember that you have to pass the correct type to PtrToStruct, otherwise itt will output the wrong type.

--
cody

Freeware Tools, Games and Humour
http://www.deutronium.de.vu || http://www.deutronium.tk


Nov 16 '05 #15

P: n/a
Thank you for response.
1) The source server was Sun (not Linux)
2) no, the client is C# and I'm cast Object (created from Byte[]) to struct
3) No problem, it works with Sun server, but I think does not with Windows
server

--
Tamir Khason
You want dot.NET? Just ask:
"Please, www.dotnet.us "

"BMermuys" <so*****@someone.com> wrote in message
news:vP***********************@phobos.telenet-ops.be...
Hi,

"Tamir Khason" <ta**********@tcon-NOSPAM.co.il> wrote in message
news:uu**************@TK2MSFTNGP10.phx.gbl...
The problem is WHAT I'M passing in.
I revieve the stream from C++ server.
When it was in UNIX enviroment - everything worked ok, but once they
treanfer to Windows the problem begun. There are same structures, but as far
as I understand , not the same stream - thet's the single explanation I

can
think about...


So, if you only see this problem when the server is on Windows and not on
Linux, you can agree that the problem is with the server and not the

client.
Can't you post some code, how do you transmit this struct in c++, do you
cast the struct* to a byte* ?

I still don't quite understand what the problem is you're having if
PtrToStruct works.

HTH,
greetings


--
Tamir Khason
You want dot.NET? Just ask:
"Please, www.dotnet.us "

"cody" <no****************@gmx.net> wrote in message
news:uE**************@TK2MSFTNGP10.phx.gbl...
> Anyway there is no way to provide full source it a lot of classes with > relations etc.
> The point is that there are diferences between unix and windows TCP or > binary stream....
I do not believe that. The bytes can be read from the stream the same way you put them in.
The marshaller will take care that the byte order (big endian/little

endian)
in your struct's variables will be ok.

Remember that you have to pass the correct type to PtrToStruct, otherwise itt will output the wrong type.

--
cody

Freeware Tools, Games and Humour
http://www.deutronium.de.vu || http://www.deutronium.tk



Nov 16 '05 #16

P: n/a
I have the same code, the only thing changed is enviroment of server (from
Sun to Windows)
I compared the packets - they are the same
the type I recieved is Object
I can post the code of reciever, but it just async C# TCP server. (bit long
for newsgroup)

--
Tamir Khason
You want dot.NET? Just ask:
"Please, www.dotnet.us "

"cody" <no****************@gmx.net> wrote in message
news:Ou**************@TK2MSFTNGP10.phx.gbl...
You should use the same pack that was used to generate the original struct. If you are not sure, compare their sizes (your struct and the receiced
packet).
If it is the same your pack size is correct.

if the cast from ObjectSerializedFromBinaryStream failed try to display the type of the generated object:

Console.WriteLine(ObjectSerializedFromBinaryStream ().GetType());

maybe that can give you the idea what got wrong.

However if you would post the piece of code you are using for receiving the packets you have much bigger chances somebody here can solve your problem.

--
cody

Freeware Tools, Games and Humour
http://www.deutronium.de.vu || http://www.deutronium.tk

Nov 16 '05 #17

P: n/a
Hi,

"Tamir Khason" <ta**********@tcon-NOSPAM.co.il> wrote in message
news:uv**************@tk2msftngp13.phx.gbl...
Thank you for response.
1) The source server was Sun (not Linux)
2) no, the client is C# and I'm cast Object (created from Byte[]) to struct

Yes, but how is the server (c++) sending this struct ?
Server-side there should be a struct to byte conversion, how is it done ?
Simple casting or is each field send seperatly ?

Greetings

3) No problem, it works with Sun server, but I think does not with Windows
server

--
Tamir Khason
You want dot.NET? Just ask:
"Please, www.dotnet.us "

"BMermuys" <so*****@someone.com> wrote in message
news:vP***********************@phobos.telenet-ops.be...
Hi,

"Tamir Khason" <ta**********@tcon-NOSPAM.co.il> wrote in message
news:uu**************@TK2MSFTNGP10.phx.gbl...
The problem is WHAT I'M passing in.
I revieve the stream from C++ server.
When it was in UNIX enviroment - everything worked ok, but once they
treanfer to Windows the problem begun. There are same structures, but
as
far
as I understand , not the same stream - thet's the single explanation
I can
think about...
So, if you only see this problem when the server is on Windows and not on Linux, you can agree that the problem is with the server and not the

client.

Can't you post some code, how do you transmit this struct in c++, do you
cast the struct* to a byte* ?

I still don't quite understand what the problem is you're having if
PtrToStruct works.

HTH,
greetings


--
Tamir Khason
You want dot.NET? Just ask:
"Please, www.dotnet.us "

"cody" <no****************@gmx.net> wrote in message
news:uE**************@TK2MSFTNGP10.phx.gbl...
> > Anyway there is no way to provide full source it a lot of classes with > > relations etc.
> > The point is that there are diferences between unix and windows
TCP or > > binary stream....
>
>
> I do not believe that. The bytes can be read from the stream the

same way
> you put them in.
> The marshaller will take care that the byte order (big endian/little
endian)
> in your struct's variables will be ok.
>
> Remember that you have to pass the correct type to PtrToStruct,

otherwise
> itt will output the wrong type.
>
> --
> cody
>
> Freeware Tools, Games and Humour
> http://www.deutronium.de.vu || http://www.deutronium.tk
>
>



Nov 16 '05 #18

P: n/a
Simple Casting. This server using its own protocol over TCP to construct
structures and I'm on other side have the same structures to recieve

--
Tamir Khason
You want dot.NET? Just ask:
"Please, www.dotnet.us "
"BMermuys" <so*****@someone.com> wrote in message
news:hv***********************@phobos.telenet-ops.be...
Hi,

"Tamir Khason" <ta**********@tcon-NOSPAM.co.il> wrote in message
news:uv**************@tk2msftngp13.phx.gbl...
Thank you for response.
1) The source server was Sun (not Linux)
2) no, the client is C# and I'm cast Object (created from Byte[]) to struct

Yes, but how is the server (c++) sending this struct ?
Server-side there should be a struct to byte conversion, how is it done ?
Simple casting or is each field send seperatly ?

Greetings

3) No problem, it works with Sun server, but I think does not with Windows
server

--
Tamir Khason
You want dot.NET? Just ask:
"Please, www.dotnet.us "

"BMermuys" <so*****@someone.com> wrote in message
news:vP***********************@phobos.telenet-ops.be...
Hi,

"Tamir Khason" <ta**********@tcon-NOSPAM.co.il> wrote in message
news:uu**************@TK2MSFTNGP10.phx.gbl...
> The problem is WHAT I'M passing in.
> I revieve the stream from C++ server.
> When it was in UNIX enviroment - everything worked ok, but once they
> treanfer to Windows the problem begun. There are same structures, but as far
> as I understand , not the same stream - thet's the single
explanation
I can
> think about...

So, if you only see this problem when the server is on Windows and not on Linux, you can agree that the problem is with the server and not the

client.

Can't you post some code, how do you transmit this struct in c++, do
you cast the struct* to a byte* ?

I still don't quite understand what the problem is you're having if
PtrToStruct works.

HTH,
greetings
>
> --
> Tamir Khason
> You want dot.NET? Just ask:
> "Please, www.dotnet.us "
>
> "cody" <no****************@gmx.net> wrote in message
> news:uE**************@TK2MSFTNGP10.phx.gbl...
> > > Anyway there is no way to provide full source it a lot of classes
with
> > > relations etc.
> > > The point is that there are diferences between unix and windows

TCP
or
> > > binary stream....
> >
> >
> > I do not believe that. The bytes can be read from the stream the

same way
> > you put them in.
> > The marshaller will take care that the byte order (big

endian/little > endian)
> > in your struct's variables will be ok.
> >
> > Remember that you have to pass the correct type to PtrToStruct,
otherwise
> > itt will output the wrong type.
> >
> > --
> > cody
> >
> > Freeware Tools, Games and Humour
> > http://www.deutronium.de.vu || http://www.deutronium.tk
> >
> >
>
>



Nov 16 '05 #19

P: n/a
Not sure what you mean with:
the type I recieved is Object


Threfore, Just the piece of code that receives the packets and re-assemble
them into the struct could be enough.

Willy.

"Tamir Khason" <ta**********@tcon-NOSPAM.co.il> wrote in message
news:O1**************@tk2msftngp13.phx.gbl...
Nov 16 '05 #20

P: n/a
Hi,

"Tamir Khason" <ta**********@tcon-NOSPAM.co.il> wrote in message
news:OA**************@TK2MSFTNGP11.phx.gbl...
Simple Casting. This server using its own protocol over TCP to construct
structures and I'm on other side have the same structures to recieve
If the server is run on Sun and the client can receive it with Pack=1, then
I suspect that structure alignment for the Sun compilation is 1 byte, not 4.

Dunno if it will help, but I don't think it's much work to see if Pack=4 for
the client helps when the server runs on Windows.
Greetings

--
Tamir Khason
You want dot.NET? Just ask:
"Please, www.dotnet.us "
"BMermuys" <so*****@someone.com> wrote in message
news:hv***********************@phobos.telenet-ops.be...
Hi,

"Tamir Khason" <ta**********@tcon-NOSPAM.co.il> wrote in message
news:uv**************@tk2msftngp13.phx.gbl...
Thank you for response.
1) The source server was Sun (not Linux)
2) no, the client is C# and I'm cast Object (created from Byte[]) to

struct

Yes, but how is the server (c++) sending this struct ?
Server-side there should be a struct to byte conversion, how is it done ?
Simple casting or is each field send seperatly ?

Greetings

3) No problem, it works with Sun server, but I think does not with Windows server

--
Tamir Khason
You want dot.NET? Just ask:
"Please, www.dotnet.us "

"BMermuys" <so*****@someone.com> wrote in message
news:vP***********************@phobos.telenet-ops.be...
> Hi,
>
> "Tamir Khason" <ta**********@tcon-NOSPAM.co.il> wrote in message
> news:uu**************@TK2MSFTNGP10.phx.gbl...
> > The problem is WHAT I'M passing in.
> > I revieve the stream from C++ server.
> > When it was in UNIX enviroment - everything worked ok, but once they > > treanfer to Windows the problem begun. There are same structures, but
as
> far
> > as I understand , not the same stream - thet's the single

explanation
I
> can
> > think about...
>
> So, if you only see this problem when the server is on Windows and

not on
> Linux, you can agree that the problem is with the server and not the
client.
>
> Can't you post some code, how do you transmit this struct in c++, do you > cast the struct* to a byte* ?
>
> I still don't quite understand what the problem is you're having if
> PtrToStruct works.
>
> HTH,
> greetings
>
>
> >
> > --
> > Tamir Khason
> > You want dot.NET? Just ask:
> > "Please, www.dotnet.us "
> >
> > "cody" <no****************@gmx.net> wrote in message
> > news:uE**************@TK2MSFTNGP10.phx.gbl...
> > > > Anyway there is no way to provide full source it a lot of classes with
> > > > relations etc.
> > > > The point is that there are diferences between unix and
windows TCP
or
> > > > binary stream....
> > >
> > >
> > > I do not believe that. The bytes can be read from the stream the

same
> way
> > > you put them in.
> > > The marshaller will take care that the byte order (big

endian/little > > endian)
> > > in your struct's variables will be ok.
> > >
> > > Remember that you have to pass the correct type to PtrToStruct,
> otherwise
> > > itt will output the wrong type.
> > >
> > > --
> > > cody
> > >
> > > Freeware Tools, Games and Humour
> > > http://www.deutronium.de.vu || http://www.deutronium.tk
> > >
> > >
> >
> >
>
>



Nov 16 '05 #21

P: n/a
You have a field of type uint in your struct. Maybe it is 32bit on windows
but it is 64 on sun, that could be the problem.

--
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:uv**************@tk2msftngp13.phx.gbl...
Thank you for response.
1) The source server was Sun (not Linux)
2) no, the client is C# and I'm cast Object (created from Byte[]) to struct 3) No problem, it works with Sun server, but I think does not with Windows
server

--
Tamir Khason
You want dot.NET? Just ask:
"Please, www.dotnet.us "

"BMermuys" <so*****@someone.com> wrote in message
news:vP***********************@phobos.telenet-ops.be...
Hi,

"Tamir Khason" <ta**********@tcon-NOSPAM.co.il> wrote in message
news:uu**************@TK2MSFTNGP10.phx.gbl...
The problem is WHAT I'M passing in.
I revieve the stream from C++ server.
When it was in UNIX enviroment - everything worked ok, but once they
treanfer to Windows the problem begun. There are same structures, but
as
far
as I understand , not the same stream - thet's the single explanation
I can
think about...
So, if you only see this problem when the server is on Windows and not on Linux, you can agree that the problem is with the server and not the

client.

Can't you post some code, how do you transmit this struct in c++, do you
cast the struct* to a byte* ?

I still don't quite understand what the problem is you're having if
PtrToStruct works.

HTH,
greetings


--
Tamir Khason
You want dot.NET? Just ask:
"Please, www.dotnet.us "

"cody" <no****************@gmx.net> wrote in message
news:uE**************@TK2MSFTNGP10.phx.gbl...
> > Anyway there is no way to provide full source it a lot of classes with > > relations etc.
> > The point is that there are diferences between unix and windows
TCP or > > binary stream....
>
>
> I do not believe that. The bytes can be read from the stream the

same way
> you put them in.
> The marshaller will take care that the byte order (big endian/little
endian)
> in your struct's variables will be ok.
>
> Remember that you have to pass the correct type to PtrToStruct,

otherwise
> itt will output the wrong type.
>
> --
> cody
>
> Freeware Tools, Games and Humour
> http://www.deutronium.de.vu || http://www.deutronium.tk
>
>



Nov 16 '05 #22

P: n/a

"cody" <no****************@gmx.net> wrote in message
news:up**************@TK2MSFTNGP09.phx.gbl...
You have a field of type uint in your struct. Maybe it is 32bit on windows
but it is 64 on sun, that could be the problem.
And don't Suns have a different endianess to x86?

--
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:uv**************@tk2msftngp13.phx.gbl...
Thank you for response.
1) The source server was Sun (not Linux)
2) no, the client is C# and I'm cast Object (created from Byte[]) to struct
3) No problem, it works with Sun server, but I think does not with Windows
server

--
Tamir Khason
You want dot.NET? Just ask:
"Please, www.dotnet.us "

"BMermuys" <so*****@someone.com> wrote in message
news:vP***********************@phobos.telenet-ops.be...
Hi,

"Tamir Khason" <ta**********@tcon-NOSPAM.co.il> wrote in message
news:uu**************@TK2MSFTNGP10.phx.gbl...
> The problem is WHAT I'M passing in.
> I revieve the stream from C++ server.
> When it was in UNIX enviroment - everything worked ok, but once they
> treanfer to Windows the problem begun. There are same structures, but as far
> as I understand , not the same stream - thet's the single
explanation
I can
> think about...

So, if you only see this problem when the server is on Windows and not on Linux, you can agree that the problem is with the server and not the

client.

Can't you post some code, how do you transmit this struct in c++, do
you cast the struct* to a byte* ?

I still don't quite understand what the problem is you're having if
PtrToStruct works.

HTH,
greetings
>
> --
> Tamir Khason
> You want dot.NET? Just ask:
> "Please, www.dotnet.us "
>
> "cody" <no****************@gmx.net> wrote in message
> news:uE**************@TK2MSFTNGP10.phx.gbl...
> > > Anyway there is no way to provide full source it a lot of classes
with
> > > relations etc.
> > > The point is that there are diferences between unix and windows

TCP
or
> > > binary stream....
> >
> >
> > I do not believe that. The bytes can be read from the stream the

same way
> > you put them in.
> > The marshaller will take care that the byte order (big

endian/little > endian)
> > in your struct's variables will be ok.
> >
> > Remember that you have to pass the correct type to PtrToStruct,
otherwise
> > itt will output the wrong type.
> >
> > --
> > cody
> >
> > Freeware Tools, Games and Humour
> > http://www.deutronium.de.vu || http://www.deutronium.tk
> >
> >
>
>



Nov 16 '05 #23

P: n/a
On Mon, 26 Jul 2004 16:28:08 +0200, "Tamir Khason"
<ta**********@tcon-NOSPAM.co.il> wrote:

<urgent plea deleted>

You, and everyone else, can drop the Urgent Urgent Urgent crap
from your posts.

Lack of planning on your part does not constititute an emergency on
our part.

Oz
--
A: Because it fouls the order in which people normally read text.
Q: Why is top-posting such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
Nov 16 '05 #24

P: n/a
> > You have a field of type uint in your struct. Maybe it is 32bit on
windows
but it is 64 on sun, that could be the problem.
And don't Suns have a different endianess to x86?


Yes, Sun has motorola byte order. Thinking about it a while I do not believe
that the marshaller converts the byteorder automatically because it doesn't
know the byteorder which the packet has. It would be great if I could tell
the marshaller to convert is automatically.
But I do not believe this has something to do which the error the OP is
getting.

--
cody

Freeware Tools, Games and Humour
http://www.deutronium.de.vu || http://www.deutronium.tk
"Stu Smith" <st*****@nospam-digita.com> schrieb im Newsbeitrag
news:O$**************@TK2MSFTNGP09.phx.gbl...
"cody" <no****************@gmx.net> wrote in message
news:up**************@TK2MSFTNGP09.phx.gbl...

--
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:uv**************@tk2msftngp13.phx.gbl...
Thank you for response.
1) The source server was Sun (not Linux)
2) no, the client is C# and I'm cast Object (created from Byte[]) to

struct
3) No problem, it works with Sun server, but I think does not with Windows server

--
Tamir Khason
You want dot.NET? Just ask:
"Please, www.dotnet.us "

"BMermuys" <so*****@someone.com> wrote in message
news:vP***********************@phobos.telenet-ops.be...
> Hi,
>
> "Tamir Khason" <ta**********@tcon-NOSPAM.co.il> wrote in message
> news:uu**************@TK2MSFTNGP10.phx.gbl...
> > The problem is WHAT I'M passing in.
> > I revieve the stream from C++ server.
> > When it was in UNIX enviroment - everything worked ok, but once they > > treanfer to Windows the problem begun. There are same structures, but
as
> far
> > as I understand , not the same stream - thet's the single explanation
I
> can
> > think about...
>
> So, if you only see this problem when the server is on Windows and

not on
> Linux, you can agree that the problem is with the server and not the
client.
>
> Can't you post some code, how do you transmit this struct in c++, do you > cast the struct* to a byte* ?
>
> I still don't quite understand what the problem is you're having if
> PtrToStruct works.
>
> HTH,
> greetings
>
>
> >
> > --
> > Tamir Khason
> > You want dot.NET? Just ask:
> > "Please, www.dotnet.us "
> >
> > "cody" <no****************@gmx.net> wrote in message
> > news:uE**************@TK2MSFTNGP10.phx.gbl...
> > > > Anyway there is no way to provide full source it a lot of classes with
> > > > relations etc.
> > > > The point is that there are diferences between unix and
windows TCP
or
> > > > binary stream....
> > >
> > >
> > > I do not believe that. The bytes can be read from the stream the

same
> way
> > > you put them in.
> > > The marshaller will take care that the byte order (big

endian/little > > endian)
> > > in your struct's variables will be ok.
> > >
> > > Remember that you have to pass the correct type to PtrToStruct,
> otherwise
> > > itt will output the wrong type.
> > >
> > > --
> > > cody
> > >
> > > Freeware Tools, Games and Humour
> > > http://www.deutronium.de.vu || http://www.deutronium.tk
> > >
> > >
> >
> >
>
>



Nov 16 '05 #25

P: n/a
Following the code
public static object RawDeserializeEx(ref byte[] rawdatas, Type anytype )
{
try
{
int rawsize = Marshal.SizeOf( anytype ) + 2;//Dont's Ask me why-This is
the structure

if( rawsize > rawdatas.Length )
return null;

GCHandle handle = GCHandle.Alloc( rawdatas, GCHandleType.Pinned );
IntPtr buffer = handle.AddrOfPinnedObject();
object retobj = Marshal.PtrToStructure( (IntPtr)(((int)buffer + 2)),
anytype ); //Dont's Ask me why-This is the structure
buffer = IntPtr.Zero;
handle.Free();
return retobj;
}
catch(Exception e)
{
ex.Handle(e);
return null;
}
}
--
Tamir Khason
You want dot.NET? Just ask:
"Please, www.dotnet.us "

"Willy Denoyette [MVP]" <wi*************@pandora.be> wrote in message
news:Ob*************@TK2MSFTNGP12.phx.gbl...
Not sure what you mean with:
the type I recieved is Object


Threfore, Just the piece of code that receives the packets and re-assemble
them into the struct could be enough.

Willy.

"Tamir Khason" <ta**********@tcon-NOSPAM.co.il> wrote in message
news:O1**************@tk2msftngp13.phx.gbl...

Nov 16 '05 #26

P: n/a
This is realy Urgent issues. I'm use this newsgoup a lot both as "asker" and
"answerer". I'm usualy do not use URGENT tag, except REALLY URGENT ISSUES
Check me... :)

BTW, nice sentence (Lack of planning on your part does not constititute an
emergency on our part.), I'll use it

--
Tamir Khason
You want dot.NET? Just ask:
"Please, www.dotnet.us "

"ozbear" <oz****@bigpond.com> wrote in message
news:4108c2db.1052057796@news-server...
On Mon, 26 Jul 2004 16:28:08 +0200, "Tamir Khason"
<ta**********@tcon-NOSPAM.co.il> wrote:

<urgent plea deleted>

You, and everyone else, can drop the Urgent Urgent Urgent crap
from your posts.

Lack of planning on your part does not constititute an emergency on
our part.

Oz
--
A: Because it fouls the order in which people normally read text.
Q: Why is top-posting such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?

Nov 16 '05 #27

P: n/a
instead of adding always 2 to the number of bytes in your method you should
declare the
field "public uint SomeId;" as "ulong" instead because the sun machine
certainly has 64 bit integers.

just a few comments:
public static object RawDeserializeEx(ref byte[] rawdatas, Type anytype )
"ref" is unnessecary because you don't modify the reference "rawdatas", just
its content.
buffer = IntPtr.Zero;
unnessecary it will automatically be freed when it goes out of scope.

--
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:eC*************@tk2msftngp13.phx.gbl... Following the code
public static object RawDeserializeEx(ref byte[] rawdatas, Type anytype )
{
try
{
int rawsize = Marshal.SizeOf( anytype ) + 2;//Dont's Ask me why-This is the structure

if( rawsize > rawdatas.Length )
return null;

GCHandle handle = GCHandle.Alloc( rawdatas, GCHandleType.Pinned );
IntPtr buffer = handle.AddrOfPinnedObject();
object retobj = Marshal.PtrToStructure( (IntPtr)(((int)buffer + 2)),
anytype ); //Dont's Ask me why-This is the structure
buffer = IntPtr.Zero;
handle.Free();
return retobj;
}
catch(Exception e)
{
ex.Handle(e);
return null;
}
}
--
Tamir Khason
You want dot.NET? Just ask:
"Please, www.dotnet.us "

"Willy Denoyette [MVP]" <wi*************@pandora.be> wrote in message
news:Ob*************@TK2MSFTNGP12.phx.gbl...
Not sure what you mean with:
the type I recieved is Object


Threfore, Just the piece of code that receives the packets and re-assemble them into the struct could be enough.

Willy.

"Tamir Khason" <ta**********@tcon-NOSPAM.co.il> wrote in message
news:O1**************@tk2msftngp13.phx.gbl...


Nov 16 '05 #28

P: n/a
TNX for reply. I'll try it

--
Tamir Khason
You want dot.NET? Just ask:
"Please, www.dotnet.us "

"cody" <no****************@gmx.net> wrote in message
news:ex**************@TK2MSFTNGP10.phx.gbl...
instead of adding always 2 to the number of bytes in your method you should declare the
field "public uint SomeId;" as "ulong" instead because the sun machine
certainly has 64 bit integers.

just a few comments:
public static object RawDeserializeEx(ref byte[] rawdatas, Type anytype )

"ref" is unnessecary because you don't modify the reference "rawdatas", just its content.
buffer = IntPtr.Zero;


unnessecary it will automatically be freed when it goes out of scope.

--
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:eC*************@tk2msftngp13.phx.gbl...
Following the code
public static object RawDeserializeEx(ref byte[] rawdatas, Type anytype ) {
try
{
int rawsize = Marshal.SizeOf( anytype ) + 2;//Dont's Ask me why-This

is
the structure

if( rawsize > rawdatas.Length )
return null;

GCHandle handle = GCHandle.Alloc( rawdatas, GCHandleType.Pinned );
IntPtr buffer = handle.AddrOfPinnedObject();
object retobj = Marshal.PtrToStructure( (IntPtr)(((int)buffer + 2)),
anytype ); //Dont's Ask me why-This is the structure
buffer = IntPtr.Zero;
handle.Free();
return retobj;
}
catch(Exception e)
{
ex.Handle(e);
return null;
}
}
--
Tamir Khason
You want dot.NET? Just ask:
"Please, www.dotnet.us "

"Willy Denoyette [MVP]" <wi*************@pandora.be> wrote in message
news:Ob*************@TK2MSFTNGP12.phx.gbl...
Not sure what you mean with:
> the type I recieved is Object

Threfore, Just the piece of code that receives the packets and

re-assemble them into the struct could be enough.

Willy.

"Tamir Khason" <ta**********@tcon-NOSPAM.co.il> wrote in message
news:O1**************@tk2msftngp13.phx.gbl...



Nov 16 '05 #29

This discussion thread is closed

Replies have been disabled for this discussion.