O'Reilly logo

.NET Common Language Runtime Unleashed by Kevin Burton

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required