Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't include windows PInvokes on Unix for System.Drawing #49405

Merged
merged 3 commits into from
Mar 11, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,6 @@
<Compile Include="System\Drawing\ClientUtils.cs" />
<Compile Include="System\Drawing\Gdiplus.cs" />
<Compile Include="System\Drawing\NativeMethods.cs" />
<Compile Include="System\Drawing\UnsafeNativeMethods.cs" />
<Compile Include="System\Drawing\Internal\ISystemEventTracker.cs" />
<Compile Include="System\Drawing\Brush.cs" />
<Compile Include="System\Drawing\Font.cs" />
Expand Down Expand Up @@ -220,6 +219,7 @@
<Compile Include="System\Drawing\SystemIcons.Windows.cs" />
<Compile Include="System\Drawing\ToolboxBitmapAttribute.cs" />
<Compile Include="System\Drawing\Text\PrivateFontCollection.Windows.cs" />
<Compile Include="System\Drawing\UnsafeNativeMethods.cs" />
safern marked this conversation as resolved.
Show resolved Hide resolved
<Compile Include="misc\DbgUtil.cs" />
<Compile Include="misc\DpiHelper.cs" />
<Compile Include="misc\ExternDll.cs" />
safern marked this conversation as resolved.
Show resolved Hide resolved
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -581,5 +581,10 @@ public object GetContextInfo()
// only known source of information @ http://blogs.wdevs.com/jdunlap/Default.aspx
safern marked this conversation as resolved.
Show resolved Hide resolved
throw new NotImplementedException();
}

private void CheckErrorStatus(int status)
{
Gdip.CheckStatus(status);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -918,5 +918,39 @@ private static void OnDomainUnload(object? sender, EventArgs e)
s_halftonePalette = IntPtr.Zero;
}
}

/// <summary>
/// GDI+ will return a 'generic error' with specific win32 last error codes when
/// a terminal server session has been closed, minimized, etc... We don't want
/// to throw when this happens, so we'll guard against this by looking at the
/// 'last win32 error code' and checking to see if it is either 1) access denied
/// or 2) proc not found and then ignore it.
///
/// The problem is that when you lock the machine, the secure desktop is enabled and
/// rendering fails which is expected (since the app doesn't have permission to draw
/// on the secure desktop). Not sure if there's anything you can do, short of catching
/// the desktop switch message and absorbing all the exceptions that get thrown while
/// it's the secure desktop.
/// </summary>
private void CheckErrorStatus(int status)
{
if (status == Gdip.Ok)
return;

// Generic error from GDI+ can be GenericError or Win32Error.
if (status == Gdip.GenericError || status == Gdip.Win32Error)
{
int error = Marshal.GetLastWin32Error();
if (error == SafeNativeMethods.ERROR_ACCESS_DENIED || error == SafeNativeMethods.ERROR_PROC_NOT_FOUND ||
// Here, we'll check to see if we are in a terminal services session...
(((UnsafeNativeMethods.GetSystemMetrics(NativeMethods.SM_REMOTESESSION) & 0x00000001) != 0) && (error == 0)))
{
return;
}
}

// Legitimate error, throw our status exception.
throw Gdip.StatusException(status);
}
}
}
34 changes: 0 additions & 34 deletions src/libraries/System.Drawing.Common/src/System/Drawing/Graphics.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2453,40 +2453,6 @@ public unsafe void TransformPoints(CoordinateSpace destSpace, CoordinateSpace sr
}
}

/// <summary>
/// GDI+ will return a 'generic error' with specific win32 last error codes when
/// a terminal server session has been closed, minimized, etc... We don't want
/// to throw when this happens, so we'll guard against this by looking at the
/// 'last win32 error code' and checking to see if it is either 1) access denied
/// or 2) proc not found and then ignore it.
///
/// The problem is that when you lock the machine, the secure desktop is enabled and
/// rendering fails which is expected (since the app doesn't have permission to draw
/// on the secure desktop). Not sure if there's anything you can do, short of catching
/// the desktop switch message and absorbing all the exceptions that get thrown while
/// it's the secure desktop.
/// </summary>
private void CheckErrorStatus(int status)
{
if (status == Gdip.Ok)
return;

// Generic error from GDI+ can be GenericError or Win32Error.
if (status == Gdip.GenericError || status == Gdip.Win32Error)
{
int error = Marshal.GetLastWin32Error();
if (error == SafeNativeMethods.ERROR_ACCESS_DENIED || error == SafeNativeMethods.ERROR_PROC_NOT_FOUND ||
// Here, we'll check to see if we are in a terminal services session...
(((UnsafeNativeMethods.GetSystemMetrics(NativeMethods.SM_REMOTESESSION) & 0x00000001) != 0) && (error == 0)))
{
return;
}
}

// Legitimate error, throw our status exception.
throw Gdip.StatusException(status);
}

/// <summary>
/// GDI+ will return a 'generic error' when we attempt to draw an Emf
/// image with width/height == 1. Here, we will hack around this by
Expand Down