By defining a struct in IDL the struct definition can be used in managed and native code.
When the IDL file is compiled the C++ bindings are automatically generated in a header file. This allows you to use the struct definition from C++.
When the resulting type library is imported by the type library importer the struct gets created along with any other visible IDL type definitions (e.g., interfaces, coclasses, enums, etc…). This creation involves translating the IDL into IL metadata (you can see the metadata with ildasm).
- Make sure the native code builds a type library and that the type library is registered.
- Use OleView to see the types included in the type library. The struct should show up in this list of types.
- Don’t typedef the struct in the IDL; although this will compile the type library importer will ignore the resulting alias. If you want the typedef for use in native code create it manually.
- Use the Object Browser or ILDASM to verify that the type library imported the struct.