Marshaling byval C-structure as return value in C#
问题 I have unmanaged code: ... typedef struct foo { int a; bool b int c; } FOO,*LPFOO; .... __declspec(dllexport) FOO __stdcall GetFoo() { FOO f; <some work> return f; } .... I've declare C# prototype for GetFoo function: [StructLayout(LayoutKind.Sequential, Pack = 1)] private struct Foo { public int a; public bool b public int c; }; [DllImport("foo.dll", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Ansi)] [return:MarshalAs( UnmanagedType.Struct)] private static extern Foo