In C# 4.0, say I have
List<HSZPAIR> myList
with three elements where the HSZPAIR struct is defined by:
[StructLayout(LayoutKind.Sequential)]
public struct HSZPAIR
{
public IntPtr hszSvc;
public IntPtr hszTopic;
}
How do I create a byte array for the entire myList? In C++, you could just cast as array of structs down to a byte array. I'm not sure how to do that in C#.
I'm using an old Windows API function in the DDEML library that requires a byte array and the number of elements in the array as arguments. If you are interested in more background, the API function is:
[DllImport("user32.dll", EntryPoint="DdeCreateDataHandle", CharSet=CharSet.Ansi)]
public static extern IntPtr DdeCreateDataHandle(int idInst, byte[] pSrc, int cb, int cbOff, IntPtr hszItem, int wFmt, int afCmd);
Here is it's documentation on MSDN. The pSrc argument is the byte array of HSZPAIR structs. The size of the array is the cb argument.