Hi,
I'm trying to port a c++ class to c# and in the c++ class I have a
struct defined as:
struct SNARLSTRUCT {
SNARL_COMMANDS cmd;
long id;
long timeout;
long lngData2;
char title[SNARL_STRING_LENGTH];
char text[SNARL_STRING_LENGTH];
char icon[SNARL_STRING_LENGTH];
};
SNARL_COMMANDS is just an enum and SNARL_STRING_LENGTH in this case is
1024.
I've recreated the struct in c# as:
[StructLayout(LayoutKind.Sequential)]
public struct SNARLSTRUCT {
public SNARL_COMMANDS cmd;
public long id;
public long timeout;
public long lngData2;
[MarshalAs(UnmanagedType.ByValArray, SizeConst=SNARL_STRING_LENGTH)]
public byte[] title;
[MarshalAs(UnmanagedType.ByValArray, SizeConst=SNARL_STRING_LENGTH)]
public byte[] text;
[MarshalAs(UnmanagedType.ByValArray, SizeConst=SNARL_STRING_LENGTH)]
public byte[] icon;
};
First of all, is this correct?
If it is, how do I go about moving data from a string to the byte
arrays and make sure they're a valid c-string representation.
Secondly, once this is correct and working, how do I use the struct as
the data part of a COPYDATASTRUCT to be sent to another window via
SendMessage() with the WM_COPYDATA message? I've seen lots of
examples on how to send simple types such as ints and strings, but not
structs.
Examples would be great (I'm a learn by example person) but pointing
to relevant docs would also be helpful.
Thanks,
Alex.