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

参数 IDispatcho 指针。

属性

例外

o 不支持请求的接口。

注解

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

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

适用于

另请参阅