Redigera

Dela via


ComWrappers.TryGetComInstance(Object, IntPtr) Method

Definition

Determines if the specified managed object is a ComWrappers-created managed wrapper and if so, returns the wrapped unmanaged pointer.

public:
 static bool TryGetComInstance(System::Object ^ obj, [Runtime::InteropServices::Out] IntPtr % unknown);
public static bool TryGetComInstance (object obj, out IntPtr unknown);
static member TryGetComInstance : obj * nativeint -> bool
Public Shared Function TryGetComInstance (obj As Object, ByRef unknown As IntPtr) As Boolean

Parameters

obj
Object

The managed wrapper.

unknown
IntPtr

nativeint

The unmanaged COM object.

Returns

true if the wrapper was resolved to an external COM object, otherwise false.

Remarks

If a COM object is returned, the caller is expected to call Release() on the object. This can be done through an API like Release(IntPtr). Since this API is required to interact directly with the external COM object, QueryInterface(), it's important for the caller to understand the COM object may have apartment affinity. Therefore, if the current thread is not in the correct apartment or the COM object is not a proxy, this call may fail.

Applies to