断言执行非托管代码的权限 [英] Asserting the permission to execute unmanaged code

查看:68
本文介绍了断言执行非托管代码的权限的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



什么是声明? (类)我需要声明允许

我的代码可以运行非托管代码。


我有:

== ==============

[System.Runtime.InteropServices.DllImport(" KERNEL32")]


private static extern bool QueryPerformanceCounter(ref long


lpPerformanceCount);


[System.Runtime.InteropServices.DllImport(" KERNEL32") ]


private static extern bool QueryPerformanceFrequency(ref long


lpFrequency);


== ==================


在调用QueryPerformanceCounter之前,我想要Assert()

许可,但我完全错过了语法,甚至没有真正的线索

关于要使用的类(例如,SecurityAction,但可能是

其他的东西):


================


静态计时()


{

//初始化频率


CodeAccessPermission perm = new SecurityAction ??? ; //<<<这里


perm.Assert();


dummy = QueryPerformanceFrequency(ref frequency);


dummy = QueryPerformanceCounter(ref fpsStartingCounter);


perm.RevertAssert();


....

==============


提前致谢,


Vanderghast,Access MVP

Hi,
What is the "declaration" (class) I need to assert the permission that
my code can run unmanaged code.

I have:
================
[System.Runtime.InteropServices.DllImport("KERNEL32 ")]

private static extern bool QueryPerformanceCounter( ref long

lpPerformanceCount);

[System.Runtime.InteropServices.DllImport("KERNEL32 ")]

private static extern bool QueryPerformanceFrequency( ref long

lpFrequency);

====================

and before calling QueryPerformanceCounter, I want to Assert() the
permission, but I completely miss the syntax, having not even a real clue
about the class to use (for illustration, SecurityAction, but probably
something else):

================

static Timings()

{
// Initialize the frequency

CodeAccessPermission perm = new SecurityAction??? ; // <<< HERE

perm.Assert();

dummy=QueryPerformanceFrequency( ref frequency);

dummy=QueryPerformanceCounter(ref fpsStartingCounter);

perm.RevertAssert();

....

==============

Thanks in advance,

Vanderghast, Access MVP


推荐答案

Michel,


你想创建一个实例SecurityPermission类的传递,从SecurityPermissionFlag枚举中的UnmanagedCode值传递



从那里,你可以调用Assert。


希望这会有所帮助。

-

- Nicholas Paldino [.NET / C#MVP]

- mv*@spam.guard.caspershouse.com


" Michel Walsh" < vanderghast @ VirusAreFunnierThanSpam>在留言中写道

news:u9 ************** @ TK2MSFTNGP14.phx.gbl ...
Michel,

You want to create an instance of the SecurityPermission class, passing
in the UnmanagedCode value from the SecurityPermissionFlag enumeration.
From there, you can call Assert.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Michel Walsh" <vanderghast@VirusAreFunnierThanSpam> wrote in message
news:u9**************@TK2MSFTNGP14.phx.gbl...

什么是声明? (类)我需要声明我的代码可以运行非托管代码的权限。

我有:

========== ======
[System.Runtime.InteropServices.DllImport(" KERNEL32")]

private static extern bool QueryPerformanceCounter(ref long

lpPerformanceCount);

[System.Runtime.InteropServices.DllImport(" KERNEL32")]

private static extern bool QueryPerformanceFrequency(ref long
lpFrequency);

====================

在调用QueryPerformanceCounter之前,我想要Assert( )
权限,但我完全错过了语法,甚至没有真正的线索关于要使用的类(例如,SecurityAction,但可能还有其他的东西):

================

静态计时()

{

/ /初始化频率

CodeAccessPermission perm = new SecurityAction ??? ; //<<<这里

perm.Assert();

dummy = QueryPerformanceFrequency(引用频率);

dummy = QueryPerformanceCounter(ref fpsStartingCounter);

perm.RevertAssert();

...

==============

提前致谢,

Vanderghast,Access MVP
Hi,
What is the "declaration" (class) I need to assert the permission that
my code can run unmanaged code.

I have:
================
[System.Runtime.InteropServices.DllImport("KERNEL32 ")]

private static extern bool QueryPerformanceCounter( ref long

lpPerformanceCount);

[System.Runtime.InteropServices.DllImport("KERNEL32 ")]

private static extern bool QueryPerformanceFrequency( ref long

lpFrequency);

====================

and before calling QueryPerformanceCounter, I want to Assert() the
permission, but I completely miss the syntax, having not even a real clue
about the class to use (for illustration, SecurityAction, but probably
something else):

================

static Timings()

{
// Initialize the frequency

CodeAccessPermission perm = new SecurityAction??? ; // <<< HERE

perm.Assert();

dummy=QueryPerformanceFrequency( ref frequency);

dummy=QueryPerformanceCounter(ref fpsStartingCounter);

perm.RevertAssert();

...

==============

Thanks in advance,

Vanderghast, Access MVP



这应该可以解决问题更安全的表格< g>):


IStackWalk perm = new SecurityPermission

SecurityPermissionFlag.UnmanagedCode);

perm.Assert( );


尝试

{

dummy = QueryPerformanceFrequency(ref frequency);

dummy = QueryPerformanceCounter(ref fpsStartingCounter);

}

终于

{

CodeAccessPermission.RevertAll();

}

" Michel Walsh" < vanderghast @ VirusAreFunnierThanSpam>在留言中写道

news:u9 ************** @ TK2MSFTNGP14.phx.gbl ...
This should do the trick (in a slightly safer form <g>):

IStackWalk perm = new SecurityPermission
SecurityPermissionFlag.UnmanagedCode);
perm.Assert();

try
{
dummy = QueryPerformanceFrequency(ref frequency);
dummy = QueryPerformanceCounter(ref fpsStartingCounter);
}
finally
{
CodeAccessPermission.RevertAll();
}
"Michel Walsh" <vanderghast@VirusAreFunnierThanSpam> wrote in message
news:u9**************@TK2MSFTNGP14.phx.gbl...

什么是声明? (类)我需要声明我的代码可以运行非托管代码的权限。

我有:

========== ======
[System.Runtime.InteropServices.DllImport(" KERNEL32")]

private static extern bool QueryPerformanceCounter(ref long

lpPerformanceCount);

[System.Runtime.InteropServices.DllImport(" KERNEL32")]

private static extern bool QueryPerformanceFrequency(ref long
lpFrequency);

====================

在调用QueryPerformanceCounter之前,我想要Assert( )
权限,但我完全错过了语法,甚至没有真正的线索关于要使用的类(例如,SecurityAction,但可能还有其他的东西):

================

静态计时()

{

/ /初始化频率

CodeAccessPermission perm = new SecurityAction ??? ; //<<<这里

perm.Assert();

dummy = QueryPerformanceFrequency(引用频率);

dummy = QueryPerformanceCounter(ref fpsStartingCounter);

perm.RevertAssert();

...

==============

提前致谢,

Vanderghast,Access MVP
Hi,
What is the "declaration" (class) I need to assert the permission that
my code can run unmanaged code.

I have:
================
[System.Runtime.InteropServices.DllImport("KERNEL32 ")]

private static extern bool QueryPerformanceCounter( ref long

lpPerformanceCount);

[System.Runtime.InteropServices.DllImport("KERNEL32 ")]

private static extern bool QueryPerformanceFrequency( ref long

lpFrequency);

====================

and before calling QueryPerformanceCounter, I want to Assert() the
permission, but I completely miss the syntax, having not even a real clue
about the class to use (for illustration, SecurityAction, but probably
something else):

================

static Timings()

{
// Initialize the frequency

CodeAccessPermission perm = new SecurityAction??? ; // <<< HERE

perm.Assert();

dummy=QueryPerformanceFrequency( ref frequency);

dummy=QueryPerformanceCounter(ref fpsStartingCounter);

perm.RevertAssert();

...

==============

Thanks in advance,

Vanderghast, Access MVP



对不起,怪异的复制粘贴工件。应该是:


IStackWalk perm = new

SecurityPermission(SecurityPermissionFlag.Unmanage dCode);

perm.Assert() ;

....

" Michel Walsh" < vanderghast @ VirusAreFunnierThanSpam>在留言中写道

news:u9 ************** @ TK2MSFTNGP14.phx.gbl ...
Sorry, weird copy-paste artifact. That should have been:

IStackWalk perm = new
SecurityPermission(SecurityPermissionFlag.Unmanage dCode);
perm.Assert();
....
"Michel Walsh" <vanderghast@VirusAreFunnierThanSpam> wrote in message
news:u9**************@TK2MSFTNGP14.phx.gbl...

什么是声明? (类)我需要声明我的代码可以运行非托管代码的权限。

我有:

========== ======
[System.Runtime.InteropServices.DllImport(" KERNEL32")]

private static extern bool QueryPerformanceCounter(ref long

lpPerformanceCount);

[System.Runtime.InteropServices.DllImport(" KERNEL32")]

private static extern bool QueryPerformanceFrequency(ref long
lpFrequency);

====================

在调用QueryPerformanceCounter之前,我想要Assert( )
权限,但我完全错过了语法,甚至没有真正的线索关于要使用的类(例如,SecurityAction,但可能还有其他的东西):

================

静态计时()

{

/ /初始化频率

CodeAccessPermission perm = new SecurityAction ??? ; //<<<这里

perm.Assert();

dummy = QueryPerformanceFrequency(引用频率);

dummy = QueryPerformanceCounter(ref fpsStartingCounter);

perm.RevertAssert();

...

==============

提前致谢,

Vanderghast,Access MVP
Hi,
What is the "declaration" (class) I need to assert the permission that
my code can run unmanaged code.

I have:
================
[System.Runtime.InteropServices.DllImport("KERNEL32 ")]

private static extern bool QueryPerformanceCounter( ref long

lpPerformanceCount);

[System.Runtime.InteropServices.DllImport("KERNEL32 ")]

private static extern bool QueryPerformanceFrequency( ref long

lpFrequency);

====================

and before calling QueryPerformanceCounter, I want to Assert() the
permission, but I completely miss the syntax, having not even a real clue
about the class to use (for illustration, SecurityAction, but probably
something else):

================

static Timings()

{
// Initialize the frequency

CodeAccessPermission perm = new SecurityAction??? ; // <<< HERE

perm.Assert();

dummy=QueryPerformanceFrequency( ref frequency);

dummy=QueryPerformanceCounter(ref fpsStartingCounter);

perm.RevertAssert();

...

==============

Thanks in advance,

Vanderghast, Access MVP



这篇关于断言执行非托管代码的权限的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆