Late-Binding to a COM Component

It is possible to avoid using tlbimp if you are willing to give up some performance and use late binding. To use late binding, your component must implement IDispatch and preferably IProvideClassInfo to provide type information about your COM methods and properties. Listing 8.7 shows a simple example of using late binding. The full source to this sample is available in the LateBinding directory.

Listing 8.7. Late Binding to a COM Component
 String progId = "COMTypes.TypeTest"; Type t = Type.GetTypeFromProgID(progId); Object o = Activator.CreateInstance(t); t.InvokeMember("Name", BindingFlags.SetProperty | BindingFlags.Public | BindingFlags.Instance, null, o, new Object[] {"Testing"} , null, null, null); Object ...

Get .NET Common Language Runtime Unleashed now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.