开发者

What does the AllowReversePInvokeCallsAttribute do?

开发者 https://www.devze.com 2023-03-26 22:43 出处:网络
I\'ve done reverse pInvoke开发者_开发技巧s and not used this attribute. I note from the documentation that it was added in 3.5 but the docs don\'t provide any example of how to use it or describe what

I've done reverse pInvoke开发者_开发技巧s and not used this attribute. I note from the documentation that it was added in 3.5 but the docs don't provide any example of how to use it or describe what it does. Can someone say what it does, and provide an example of how it might be used and when it is needed?


The comment in the Reference Source gives some insight:

// To be used on methods that sink reverse P/Invoke calls.
// This attribute is a CoreCLR-only security measure, currently ignored by the desktop CLR.
[AttributeUsage(AttributeTargets.Method, AllowMultiple = false, Inherited = false)]
public sealed class AllowReversePInvokeCallsAttribute : Attribute
{
    public AllowReversePInvokeCallsAttribute()
    {
    }
}

CoreCLR is the CLR version that drives Silverlight. Big on sandboxing. You won't find it used at all in the desktop version but all over the place in the Silverlight assemblies. Samples are the MS.Internal.FrameworkCallbacks class and the System.Windows namespace. Have a look-see with Reflector. The intention is clear, when the CLR marshals a call from native to managed, it checks if the managed method is expected to be invoked.


It's not suppose to be used:

This API supports the .NET Framework infrastructure and is not intended to be used directly from your code.

0

精彩评论

暂无评论...
验证码 换一张
取 消