|
3090 | 3090 |
|
3091 | 3091 | In the .NET Framework 2.0 and later versions, you can use the <xref:System.Runtime.InteropServices.Marshal.GetDelegateForFunctionPointer%2A> and <xref:System.Runtime.InteropServices.Marshal.GetFunctionPointerForDelegate%2A> methods to marshal delegates in both directions. With <xref:System.Runtime.InteropServices.Marshal.GetDelegateForFunctionPointer%2A>, `ptr` is imported as a <xref:System.IntPtr?displayProperty=nameWithType>. A <xref:System.IntPtr?displayProperty=nameWithType> can be obtained for a managed delegate by calling <xref:System.Runtime.InteropServices.Marshal.GetFunctionPointerForDelegate%2A> and passed as a parameter; it can then be called from inside the unmanaged method. Note that the parameter marshaler can also marshal function pointers to delegates in the .NET Framework 2.0 and later versions.
|
3092 | 3092 |
|
3093 |
| - The <xref:System.Runtime.InteropServices.Marshal.GetDelegateForFunctionPointer%2A> method has the following restrictions: |
| 3093 | + `ptr` is converted to a delegate that invokes the unmanaged method using the [__stdcall](/cpp/cpp/stdcall) calling convention on Windows, or the [__cdecl](/cpp/cpp/cdecl) calling convention on Linux and macOS. You can set the calling convention by applying the <xref:System.Runtime.InteropServices.UnmanagedFunctionPointerAttribute> to the delegate. |
3094 | 3094 |
|
3095 |
| -- Generics are not supported in interop scenarios. |
| 3095 | + The <xref:System.Runtime.InteropServices.Marshal.GetDelegateForFunctionPointer%2A> method has the following restrictions: |
3096 | 3096 |
|
3097 |
| -- You cannot pass an invalid function pointer to this method. |
| 3097 | +- Generics are not supported in interop scenarios. |
3098 | 3098 |
|
3099 | 3099 | - You can use this method only for pure unmanaged function pointers.
|
3100 | 3100 |
|
3101 |
| -- You cannot use this method with function pointers obtained through C++ or from the <xref:System.RuntimeMethodHandle.GetFunctionPointer%2A> method. |
3102 |
| - |
3103 |
| -- You cannot use this method to create a delegate from a function pointer to another managed delegate. |
| 3101 | +- You cannot use this method with function pointers obtained through C++. |
3104 | 3102 |
|
3105 | 3103 | ]]></format>
|
3106 | 3104 | </remarks>
|
|
3167 | 3165 | ## Remarks
|
3168 | 3166 | You can use the <xref:System.Runtime.InteropServices.Marshal.GetDelegateForFunctionPointer%60%601%28System.IntPtr%29> and <xref:System.Runtime.InteropServices.Marshal.GetFunctionPointerForDelegate%60%601%28%60%600%29> methods to marshal delegates in both directions.
|
3169 | 3167 |
|
| 3168 | + `ptr` is converted to a delegate that invokes the unmanaged method using the [__stdcall](/cpp/cpp/stdcall) calling convention on Windows, or the [__cdecl](/cpp/cpp/cdecl) calling convention on Linux and macOS. You can set the calling convention by applying the <xref:System.Runtime.InteropServices.UnmanagedFunctionPointerAttribute> to the delegate. |
| 3169 | + |
3170 | 3170 | The <xref:System.Runtime.InteropServices.Marshal.GetDelegateForFunctionPointer%60%601%28System.IntPtr%29> method has the following restrictions:
|
3171 | 3171 |
|
3172 |
| -- You cannot pass an invalid function pointer to this method. |
| 3172 | +- Generics are not supported in interop scenarios. |
3173 | 3173 |
|
3174 | 3174 | - You can use this method only for pure unmanaged function pointers.
|
3175 | 3175 |
|
3176 |
| -- You cannot use this method with function pointers obtained through C++ or from the <xref:System.RuntimeMethodHandle.GetFunctionPointer%2A> method. |
3177 |
| - |
3178 |
| -- You cannot use this method to create a delegate from a function pointer to another managed delegate. |
| 3176 | +- You cannot use this method with function pointers obtained through C++. |
3179 | 3177 |
|
3180 | 3178 | ]]></format>
|
3181 | 3179 | </remarks>
|
|
0 commit comments