about [SuppressUnmanagedCodeSecurity]

  • Thread starter Thread starter Lloyd Dupont
  • Start date Start date
L

Lloyd Dupont

I'm not exactly sur in which context it is valid / usefull.

For example will it suppres the stack in the following sample below when
using the ScreenGraphics class?
(i.e. I wonder if it will work even if it is not applied to the Gdi32 class,
but to the "consumer" class ScreenGraphics instead...)

internal static class Gdi32
{
[DllExport("GDI32")]
public static extern IntPtr GetHdc(IntPtr hWnd);
}
[SuppressUnmanagedCodeSecurity]
public class ScreenGraphics
{
public Graphics Graphics
{
get
{
IntPtr hdc = Gdi32.GetHdc(IntPtr.Zero);
return Graphics.FromHdc(hdc);
}
}
}
 
Hi Lloyd,

Lloyd Dupont said:
I'm not exactly sur in which context it is valid / usefull.

For example will it suppres the stack in the following sample below when
using the ScreenGraphics class?
(i.e. I wonder if it will work even if it is not applied to the Gdi32
class, but to the "consumer" class ScreenGraphics instead...)

internal static class Gdi32
{
[DllExport("GDI32")]
public static extern IntPtr GetHdc(IntPtr hWnd);
}
[SuppressUnmanagedCodeSecurity]
public class ScreenGraphics
{
public Graphics Graphics
{
get
{
IntPtr hdc = Gdi32.GetHdc(IntPtr.Zero);
return Graphics.FromHdc(hdc);
}
}
}

You should apply [SuppressUnmanagedCodeSecurity] to P/Invoke functions or to
types implementing P/Invoke functions - not to types using them.
 
Hi Marcus,
Thanks for the information!
Too bad for the info itself :-(

Marcus Heege said:
Hi Lloyd,

Lloyd Dupont said:
I'm not exactly sur in which context it is valid / usefull.

For example will it suppres the stack in the following sample below when
using the ScreenGraphics class?
(i.e. I wonder if it will work even if it is not applied to the Gdi32
class, but to the "consumer" class ScreenGraphics instead...)

internal static class Gdi32
{
[DllExport("GDI32")]
public static extern IntPtr GetHdc(IntPtr hWnd);
}
[SuppressUnmanagedCodeSecurity]
public class ScreenGraphics
{
public Graphics Graphics
{
get
{
IntPtr hdc = Gdi32.GetHdc(IntPtr.Zero);
return Graphics.FromHdc(hdc);
}
}
}

You should apply [SuppressUnmanagedCodeSecurity] to P/Invoke functions or
to types implementing P/Invoke functions - not to types using them.
 
Back
Top