Class ComMarshalling
- Namespace
- CsCom.Runtime
- Assembly
- CsCom.Runtime.dll
Configures how the support code converts COM interface pointers to managed objects and back.
public static class ComMarshalling
- Inheritance
-
ComMarshalling
- Inherited Members
Properties
ComWrappers
Gets or sets the StrategyBasedComWrappers that creates the managed objects of COM objects and the COM interfaces of managed objects; null, the default, for the instance that ComInterfaceMarshaller<T> of .NET uses.
public static StrategyBasedComWrappers? ComWrappers { get; set; }
Property Value
Remarks
The instance is used by ComActivator, by the VARIANT and SAFEARRAY marshallers, by the
late-bound wrappers and the event sinks, and by ComObjectMarshaller<T> and
UniqueComObjectMarshaller<T>, which the generated code applies to all interface pointers. Other code
that marshals interface pointers with ComInterfaceMarshaller<T>, such as hand-written COM interfaces
without these marshallers, does not use it.
The marshalled interfaces must be source-generated COM interfaces (GeneratedComInterfaceAttribute), also when the instance has a strategy of its own for the details of interfaces: their identifiers are taken from the attributes that the generator adds.
Set it once, before the first COM object is created: two instances create two managed objects for one COM object.
Exceptions
- InvalidOperationException
The value is changed after the support code converted an interface pointer.
Methods
IsExposedToCom(object?)
Gets a value indicating whether the support code exposes an object to COM itself: its class is a source-generated
COM class (GeneratedComClassAttribute). Such an object is passed as its own COM interface in a
VARIANT, a SAFEARRAY and an IUnknown parameter alike, also when it implements
IDispatchProvider, so that its pointer converts back to it, and Release(object?) leaves it alone.
public static bool IsExposedToCom(object? value)
Parameters
Returns
- bool
true if the class of the object is a source-generated COM class; false otherwise, also for null, a COM object and a late-bound or
dynamicwrapper.
Remarks
The test is the same whatever ComWrappers is set: it reads the class with the strategy of .NET that reads the identifiers of the interfaces, so that the same values are passed with every instance, and it does not use the instance, which can still be set afterwards. Pass an object that only a custom instance exposes in an System.Runtime.InteropServices.UnknownWrapper. One that implements IDispatchProvider is a late-bound wrapper all the same, which stands for the COM object of its Dispatch, also in an System.Runtime.InteropServices.UnknownWrapper and in a parameter of a COM interface that it implements.
Release(object?)
Releases the COM references of a unique object at once, like FinalRelease(); the object must not be used afterwards. Nothing happens for other objects: a shared object keeps its references until it is garbage collected, and a managed object has none. The COM object that a shared conversion creates for the pointer of a managed object for an interface that the object does not implement is not shared (see ComObjectMarshaller<T>), and is released.
public static void Release(object? value)
Parameters
valueobjectThe object: a COM interface, or a late-bound wrapper or
dynamicobject, whose COM object is released; can be null. A managed object that is exposed to COM (GeneratedComClassAttribute) is left alone, also when it implements IDispatchProvider. An System.Runtime.InteropServices.UnknownWrapper stands for its object, and a System.Runtime.InteropServices.DispatchWrapper is rejected, as where an object is passed to COM.
Remarks
Release an object only when no other thread uses it: a call that passes it to a COM object at the same time can use its interface pointer after the release.
Exceptions
- ArgumentException
The value is, or wraps, a System.Runtime.InteropServices.DispatchWrapper.