Home All Groups Group Topic Archive Search About

Safe / Unsafe Native Methods

Author
9 May 2006 1:11 PM
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.

Author
9 May 2006 7:16 PM
Mattias Sjögren
>    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

--
Mattias Sjögren [C# MVP]  mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Author
12 May 2006 1:48 PM
NickP
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.