none
Structure Marshal to C# RRS feed

  • Question

  • Hi,

    I need to write C# client application which needs to send the structure over pipe. The server appliacation is writen in C++.

    The structure I need to send looks like this in C++:

    struct SomeData
    {
        wchar_t name1[30];
        wchar_t name2[256];
        __int32  pid;
        VIDEOINFOHEADER vih;
    };

    What would be the proper way to marshal this structure?
    Note that VIDEOINFOHEADER can be replaced with some fixed bytes of same length.

    Thanks!

    Wednesday, November 13, 2019 1:29 PM

Answers

  • Something like :

            [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
            public struct SomeData
            {
                [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 30)]
                public string name1;
                [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 256)]
                public string name2;
                public int pid;
                public VIDEOINFOHEADER vih;
            }

    • Marked as answer by iz111 Wednesday, November 13, 2019 1:57 PM
    Wednesday, November 13, 2019 1:53 PM