Marshal SizeOf

  • Thread starter Thread starter Asaf Shelly
  • Start date Start date
A

Asaf Shelly

Hi All,

I am sending a struct with a member buffer using Interop. It looks like the
marshaler knows the length of the buffer and sends only that length.
The question is how can I know the size of the buffer before it is sent?

TIA,
Asaf
 
I am sending a struct with a member buffer using Interop. It looks like the
marshaler knows the length of the buffer and sends only that length.
The question is how can I know the size of the buffer before it is sent?

What is wrong with the call mentioned in the subject
line (Marshal.SizeOf) ?

Arne
 
Hi All,

I am sending a struct with a member buffer using Interop. It looks like the
marshaler knows the length of the buffer and sends only that length.
The question is how can I know the size of the buffer before it is sent?

Hmmm... What are you asking? Is not the answer in your subject line?
 
Hi Arne and Tom,

The format is:
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi, Pack = 1)]
public class TEST
{
[MarshalAs(UnmanagedType.ByValArray)]
public byte[] Buffer;
}

where buffer is allocated later. The Interop system knows to send the
correct number of bytes, so even if I specify "SizeConst = 55" and the buffer
is 15 bytes then only 15 bytes will be sent.

My problem is that I need to know in advance the number of bytes that need
to be sent because I need to notify the other end of the stream.

Any idea how the system knows the length of the object in bytes. SizeOf does
not work and I would really hate having to enumerate all members..

Thanks,
Asaf
 
Back
Top