How To Make A Suitable .DLL for type-library conversion

115 views Asked by At

I have incomplete types from my COM type library .tlb (which was generated by regasm OF .NET v4+) I am unsure if this is because cppc.exe derived the wrong header for it or if this is merely a symptom of it. I know it's incomplete because all the generated classes come out a. as structs and b. with empty interface bodies (no methods defined).

I'm sure I've done something wrong when making my .dll suitable for regasm; I've changed the Assembly-Info and I've made default constructors for-all types. Was I meant to do something else maybe?

1

There are 1 answers

1
Aurora On BEST ANSWER

If you mark your assembly as COM-visible, all public classes with a default constructor are exposed with the help of a dispinterface. This interface type is designed for late bound clients, such as scripting languages, which invoke methods and properties via Dispatch identifiers (DISPIDs). An accompanying type library won't contain any entries for the interface.

In order to bind to a fixed layout, you’ll need to switch to a dual or IUnknown interface. Simply edit your AssemblyInfo.cs as follows:

// Setting ComVisible to false makes the types in this assembly not visible
// to COM components.  If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(true)]
[assembly: ClassInterface(ClassInterfaceType.AutoDual)]

Now, the methods of the interface are visible in the type library, as well as in IntelliSense.

Note however that with an AutoDual exposed class, you'll need to need to take care when updating the assembly. See this link for further info.