|
How Do I...Build a .NET Client That Uses a COM Server?This section explains how to build managed code that uses COM. The steps involved in the build process are as follows:
Obtain an Assembly Containing Definitions of the COM Types to be UsedBefore any managed application can reference a specific type, the type must be described in metadata. For managed types, this is easy because the compiler that produces the managed code also produces the necessary metadata. Getting metadata for existing COM types is a little trickier. There are several ways to do this.
Install the Assembly in the Global Assembly CacheIf you want your assembly containing definitions of the COM types to be shared among several applications, it must be installed in the global assembly cache (GAC). Use gacutil.exe to install an assembly in the GAC.
gacutil /i ExplorerLib.dll Reference the Assembly Containing the Type Definitions.With Visual Basic .NET or with C#, you can reference the assembly using the compiler /r switch or you can add reference to the project directly from Visual Studio .NET development tool.
vbc TestClient.vb /r:ExplorerLib.dll VB
Reference the COM TypesOnce the reference to the type library is added to the project, the types defined within that library can be referenced from managed code. Refer to the How Do I...Call COM methods from .NET? for an example on how to do that.Note: See the article on http://support.microsoft.com/support/misc/kblookup.asp?id=Q264957 when using VB6 components from managed code.
|