Safe / Unsafe Native Methods

  • Thread starter Thread starter NickP
  • Start date Start date
N

NickP

Hi there,

I am currently moving my API declarations into relevant classes for Safe
and Unsafe methods. My understanding is that unsafe methods are ones that
require elevated security priviledges in order to perform their function.
Is there a reference available as to what methods are safe and which unsafe?

For example I cam currently looking at the method SHGetFileInfo, I
presume this is unsafe as you would need to have priviledges in order to
view the information on specific files. Any advice on this would be greatly
appreciated.

Also, one other quick thing. Presumable <DllImport()> can be used for
*all* API declarations? I am making them all declared in a consistent way
and thought I'd best check that I'm not going to run into any weird
problems.

Cheers again and thanks in advance for any help!

Nick.
 
I am currently moving my API declarations into relevant classes for Safe
and Unsafe methods. My understanding is that unsafe methods are ones that
require elevated security priviledges in order to perform their function.
Is there a reference available as to what methods are safe and which unsafe?

For example I cam currently looking at the method SHGetFileInfo, I
presume this is unsafe as you would need to have priviledges in order to
view the information on specific files. Any advice on this would be greatly
appreciated.

Do you use the SuppressUnmanagedCodeSecurity attribute? If not, it
doesn't really matter if you consider a function safe or unsafe, any
calling code will need permission to call unmanaged code (which
basically means it needs full trust).

Also, one other quick thing. Presumable <DllImport()> can be used for
*all* API declarations?

Yes


Mattias
 
Hi Mattias,
Do you use the SuppressUnmanagedCodeSecurity attribute? If not, it
doesn't really matter if you consider a function safe or unsafe, any
calling code will need permission to call unmanaged code (which
basically means it needs full trust).
Yup.

Yes

Okay cool, I guess its just a matter of trial and error to see if the
attribute causes any issues than. Thanks for your help, much appreciated.

Nick.
 
Back
Top