Calling COM from .NET Code

Most likely a programmer will want to use old COM-based code in new .NET applications (rather than the other way around), for the simple reason that there is probably much more COM code out there than .NET code. (Eventually the momentum will shift and COM will likely be left by the roadside somewhere, but that day is still a long way off.) Let's start with how the mechanism for using COM in .NET works in general, and then we'll continue with an example.

When you want to use an old VB6 COM object (or some other language-based COM object) in .NET, .NET wraps a runtime callable wrapper (RCW) around the COM binary. This RCW manifests itself as an assembly named Interop.<assemblyname>.dll, where <assemblyname> is the name ...

Get Visual Basic® .NET Power Coding 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.