> > I recently had to use someone's struct from a native app to receive data over
> > Udp. The struct has a array member which looked like this:
[quoted text clipped - 45 lines]
>
> Tom
Nick,
I think ref struct is almost the same as ref class, the only difference
is whether members are public or private by default.
No, I don't think you should pass a ref class to unmanaged code.
Although it may seem your class is not inherited from anything and it
only declares one member, it actually is inherited from System::Object,
the parent of all .NET classes, and it most likely has implicit members
that you don't know of. Most importantly, you don't know the memory
layout, and you don't know what's inside the array container (I
guarantee you it's not a raw storage, it has further members, such as
the length of the array). You should only pin the handle to the array's
first item:
cli::pin_ptr<char> s( & sName[0] );
sizeof(sensorHrd) is most likely not 64. Don't rely on that. Instead,
use sName->Length to get the number of items in the array (which is the
size of the array in bytes in your case).
I think a .NET array is guaranteed to be contiguous in the memory, at
least this link claims it is:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dv_vstechart/ht
ml/datastructures_guide.asp
Most containers aren't, but array is, as long as it stores value types
(such as char).
BTW, you have two more options: System::String, and memory stream. They
both allocate contiguous memory. I'd still use array<char>, which is a
wrapper around System::Array. Would use memory stream if I wanted to
append data dynamically to it.
Tom
> Tamas,
>
[quoted text clipped - 7 lines]
>
> Nick