How Do I... Get Started Using Interoperability?
The common language runtime's COM interoperability services make it possible to use existing COM
objects from within managed applications and expose managed objects to existing COM applications.
Note: Managed code is code that targets the common language runtime.
In addition, the runtime's platform invoke mechanism makes it possible to call functions exported
from unmanaged DLLs. One of the QuickStarts in this area is devoted to demonstrating COM interoperability
and platform invoke.
COM Interoperability
COM interoperability provides support for producing and consuming COM
objects from managed code.
Objects that are intended to be consumed
by COM applications must be designed with interoperability in mind right from the start.
Before a type can be consumed by a COM application, the
type must meet the following requirements.
- The managed type (class, interface, struct or enum) must be public.
- It is strongly recommended that the class explicitly implement an interface instead of
exposing class interface, which contains all of the members of the class and all the members
of its base classes.
- The members of the type that are being accessed from COM must
be public, non-static instance members. Private, protected, internal, and static members
are not accessible.
- If you need to create the type from COM, it must have a public, default (parameterless)
constructor.
See the
How Do I...Build a .NET COM Server Callable from COM clients? topic for details on the build process.
COM interoperability provides mechanisms that make it possible to use COM objects from
managed code as well. This is the mechanism that runtime clients use to access the services provided
by COM objects. Before any managed client can reference a specific COM type, the type must
be described in metadata.
See the
How Do I...Build a .NET Client That Uses a COM Server? topic for details on obtaining
an assembly containing metadata for the COM types and the build process.
Platform Invoke
The platform invoke service makes it possible to call functions that are exported from an
unmanaged DLL. Using platform invoke is similar to calling the LoadLibrary and GetProcAddress
Win32 API functions, which call into an exported function. It is also similar to using a
Declare statement in Visual Basic.
Each exported function being called must have a managed method definition. The
method definition can be provided as part of any class and is attributed with the DllImport
attribute in C# or with Declare statement in VB.NET to indicate that the method is
implemented in unmanaged code.
See the
How Do I...Call a Function Exported From an Unmanaged Library? topic for details on
the platform invoke syntax.
Microsoft .NET Framework SDK QuickStart Tutorials Version 2.0
Copyright � 2004 Microsoft Corporation. All rights reserved.
|