Marshal.GetIDispatchForObject(Object) 方法

定义

从托管对象返回一个 IDispatch 接口。

public:
 static IntPtr GetIDispatchForObject(System::Object ^ o);
[System.Runtime.Versioning.SupportedOSPlatform("windows")]
public static IntPtr GetIDispatchForObject (object o);
public static IntPtr GetIDispatchForObject (object o);
[System.Security.SecurityCritical]
public static IntPtr GetIDispatchForObject (object o);
[<System.Runtime.Versioning.SupportedOSPlatform("windows")>]
static member GetIDispatchForObject : obj -> nativeint
static member GetIDispatchForObject : obj -> nativeint
[<System.Security.SecurityCritical>]
static member GetIDispatchForObject : obj -> nativeint
Public Shared Function GetIDispatchForObject (o As Object) As IntPtr

参数

o
Object

IDispatch 接口被请求的对象。

返回

IntPtr

nativeint

o 参数的 IDispatch 指针。

属性

例外

o 不支持请求的接口。

注解

在托管代码中,很少直接使用 IDispatch 接口。 但是, GetIDispatchForObject 在调用将 COM 对象参数公开为 IntPtr 类型或使用自定义封送处理的方法时很有用。 使用此方法调用 对象会导致接口指针上的引用计数在返回指针之前递增。 使用完指针后,始终使用 Marshal.Release 来递减引用计数。

还可以在托管对象上使用此方法,以获取指向该对象的 COM 可调用包装器的接口指针。 有关详细信息,请参阅 COM 可调用包装器

适用于

另请参阅