473,320 Members | 2,158 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

URGENT: Unix/Windows Struct cast problem

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
28 2985
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
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
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
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

"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
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
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
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
> 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
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
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
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
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
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
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
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
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
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
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
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
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

"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
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
> > 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
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Harbinger of Doom | last post by:
Hello, I'm currently working on a program that has to read values from the windows registry. I use the functions "RegOpenKeyEx", "RegCloseKey" and "RegQueryValueEx" for that. If I can read the...
9
by: Stefan Bauer | last post by:
Hi NG, we've got a very urgent problem... :( We are importing data with the LOAD utility. The input DATE field data is in the format DDMMYYYY (for days) and MMYYYY (for months). The target...
3
by: Emanuele Blanco | last post by:
Hi there, I just compiled a program that uses linked lists (needed it as an homework for my Programming course at University). It works flawlessly, even if I notice a thing. Here's my linked...
20
by: fix | last post by:
Hi all, I feel unclear about what my code is doing, although it works but I am not sure if there is any possible bug, please help me to verify it. This is a trie node (just similar to tree nodes)...
8
by: ginnisharma1 | last post by:
Hi All, I am very new to C language and I got really big assignment in my work.I am wondering if anyone can help me.........I need to port compiler from unix to windows and compiler is written...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.