Marshal.GetDelegateForFunctionPointer Método
Definición
Sobrecargas
GetDelegateForFunctionPointer(IntPtr, Type) |
Obsoleto.
Convierte un puntero a función no administrada en un delegado.Converts an unmanaged function pointer to a delegate. |
GetDelegateForFunctionPointer<TDelegate>(IntPtr) |
[Compatible con .NET Framework 4.5.1 y versiones posteriores][Supported in the .NET Framework 4.5.1 and later versions] Convierte un puntero a función no administrada en un delegado de un tipo especificado.Converts an unmanaged function pointer to a delegate of a specified type. |
GetDelegateForFunctionPointer(IntPtr, Type)
Precaución
GetDelegateForFunctionPointer(IntPtr, Type) may be unavailable in future releases. Instead, use GetDelegateForFunctionPointer
Convierte un puntero a función no administrada en un delegado.Converts an unmanaged function pointer to a delegate.
public:
static Delegate ^ GetDelegateForFunctionPointer(IntPtr ptr, Type ^ t);
[System.Obsolete("GetDelegateForFunctionPointer(IntPtr, Type) may be unavailable in future releases. Instead, use GetDelegateForFunctionPointer<T>(IntPtr). For more info, go to http://go.microsoft.com/fwlink/?LinkID=296521")]
[System.Security.SecurityCritical]
public static Delegate GetDelegateForFunctionPointer (IntPtr ptr, Type t);
public static Delegate GetDelegateForFunctionPointer (IntPtr ptr, Type t);
[System.Security.SecurityCritical]
public static Delegate GetDelegateForFunctionPointer (IntPtr ptr, Type t);
[<System.Obsolete("GetDelegateForFunctionPointer(IntPtr, Type) may be unavailable in future releases. Instead, use GetDelegateForFunctionPointer<T>(IntPtr). For more info, go to http://go.microsoft.com/fwlink/?LinkID=296521")>]
[<System.Security.SecurityCritical>]
static member GetDelegateForFunctionPointer : nativeint * Type -> Delegate
static member GetDelegateForFunctionPointer : nativeint * Type -> Delegate
[<System.Security.SecurityCritical>]
static member GetDelegateForFunctionPointer : nativeint * Type -> Delegate
Public Shared Function GetDelegateForFunctionPointer (ptr As IntPtr, t As Type) As Delegate
Parámetros
- ptr
- IntPtr
Puntero a función no administrada que se va a convertir.The unmanaged function pointer to be converted.
- t
- Type
Tipo del delegado que se va a devolver.The type of the delegate to be returned.
Devoluciones
Instancia de delegado que se puede convertir al tipo de delegado adecuado.A delegate instance that can be cast to the appropriate delegate type.
- Atributos
Excepciones
El parámetro t
no es un delegado o es genérico.The t
parameter is not a delegate or is generic.
El parámetro ptr
es null
.The ptr
parameter is null
.
o bien-or-
El parámetro t
es null
.The t
parameter is null
.
Comentarios
En las versiones 1,0 y 1,1 del .NET Framework, era posible pasar un delegado que representa un método administrado a código no administrado como un puntero de función, lo que permite al código no administrado llamar al método administrado a través del puntero de función.In versions 1.0 and 1.1 of the .NET Framework, it was possible to pass a delegate representing a managed method to unmanaged code as a function pointer, allowing the unmanaged code to call the managed method through the function pointer. También era posible que el código no administrado pasara ese puntero de función al código administrado, y el puntero se resolviera correctamente en el método administrado subyacente.It was also possible for the unmanaged code to pass that function pointer back to the managed code, and the pointer was resolved properly to the underlying managed method.
En el .NET Framework 2,0 y versiones posteriores, puede usar los GetDelegateForFunctionPointer métodos y GetFunctionPointerForDelegate para calcular las referencias de los delegados en ambas direcciones.In the .NET Framework 2.0 and later versions, you can use the GetDelegateForFunctionPointer and GetFunctionPointerForDelegate methods to marshal delegates in both directions. Con GetDelegateForFunctionPointer , ptr
se importa como System.IntPtr .With GetDelegateForFunctionPointer, ptr
is imported as a System.IntPtr. Un System.IntPtr se puede obtener para un delegado administrado mediante una llamada a GetFunctionPointerForDelegate y se pasa como parámetro; a continuación, se le puede llamar desde dentro del método no administrado.A System.IntPtr can be obtained for a managed delegate by calling GetFunctionPointerForDelegate and passed as a parameter; it can then be called from inside the unmanaged method. Tenga en cuenta que el contador de referencias de parámetros también puede serializar los punteros de función a los delegados en la .NET Framework 2,0 y versiones posteriores.Note that the parameter marshaler can also marshal function pointers to delegates in the .NET Framework 2.0 and later versions.
ptr
se convierte en un delegado que invoca el método no administrado mediante el __stdcall Convención de llamada en Windows o la Convención de llamada __cdecl en Linux y MacOS.ptr
is converted to a delegate that invokes the unmanaged method using the __stdcall calling convention on Windows, or the __cdecl calling convention on Linux and macOS. Puede establecer la Convención de llamada aplicando UnmanagedFunctionPointerAttribute al delegado.You can set the calling convention by applying the UnmanagedFunctionPointerAttribute to the delegate.
El GetDelegateForFunctionPointer método tiene las restricciones siguientes:The GetDelegateForFunctionPointer method has the following restrictions:
Los genéricos no se admiten en escenarios de interoperabilidad.Generics are not supported in interop scenarios.
Este método solo se puede usar para punteros de función no administrados puros.You can use this method only for pure unmanaged function pointers.
No se puede usar este método con punteros de función obtenidos a través de C++.You cannot use this method with function pointers obtained through C++.
Se aplica a
GetDelegateForFunctionPointer<TDelegate>(IntPtr)
[Compatible con .NET Framework 4.5.1 y versiones posteriores][Supported in the .NET Framework 4.5.1 and later versions]
Convierte un puntero a función no administrada en un delegado de un tipo especificado.Converts an unmanaged function pointer to a delegate of a specified type.
public:
generic <typename TDelegate>
static TDelegate GetDelegateForFunctionPointer(IntPtr ptr);
[System.Security.SecurityCritical]
public static TDelegate GetDelegateForFunctionPointer<TDelegate> (IntPtr ptr);
public static TDelegate GetDelegateForFunctionPointer<TDelegate> (IntPtr ptr);
[<System.Security.SecurityCritical>]
static member GetDelegateForFunctionPointer : nativeint -> 'Delegate
static member GetDelegateForFunctionPointer : nativeint -> 'Delegate
Public Shared Function GetDelegateForFunctionPointer(Of TDelegate) (ptr As IntPtr) As TDelegate
Parámetros de tipo
- TDelegate
Tipo del delegado que se va a devolver.The type of the delegate to return.
Parámetros
- ptr
- IntPtr
Puntero a función no administrada que se va a convertir.The unmanaged function pointer to convert.
Devoluciones
- TDelegate
Una instancia del tipo de delegado especificado.A instance of the specified delegate type.
- Atributos
Excepciones
El parámetro genérico TDelegate
no es un delegado o es un tipo genérico abierto.The TDelegate
generic parameter is not a delegate, or it is an open generic type.
El parámetro ptr
es null
.The ptr
parameter is null
.
Comentarios
Puede usar los GetDelegateForFunctionPointer<TDelegate>(IntPtr) métodos y GetFunctionPointerForDelegate<TDelegate>(TDelegate) para calcular las referencias de los delegados en ambas direcciones.You can use the GetDelegateForFunctionPointer<TDelegate>(IntPtr) and GetFunctionPointerForDelegate<TDelegate>(TDelegate) methods to marshal delegates in both directions.
ptr
se convierte en un delegado que invoca el método no administrado mediante el __stdcall Convención de llamada en Windows o la Convención de llamada __cdecl en Linux y MacOS.ptr
is converted to a delegate that invokes the unmanaged method using the __stdcall calling convention on Windows, or the __cdecl calling convention on Linux and macOS. Puede establecer la Convención de llamada aplicando UnmanagedFunctionPointerAttribute al delegado.You can set the calling convention by applying the UnmanagedFunctionPointerAttribute to the delegate.
El GetDelegateForFunctionPointer<TDelegate>(IntPtr) método tiene las restricciones siguientes:The GetDelegateForFunctionPointer<TDelegate>(IntPtr) method has the following restrictions:
Los genéricos no se admiten en escenarios de interoperabilidad.Generics are not supported in interop scenarios.
Este método solo se puede usar para punteros de función no administrados puros.You can use this method only for pure unmanaged function pointers.
No se puede usar este método con punteros de función obtenidos a través de C++.You cannot use this method with function pointers obtained through C++.