Skip to content
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
Prev Previous commit
Use StartupInputEx instead of StartupInput to ensure that we're initi…
…alizing GDI+ v2 consistently.
  • Loading branch information
jkoritzinsky committed Feb 9, 2022
commit 86c0f5bb823a864f06e5c411e0dbe0f9ef9cb4a6
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,9 @@ static Gdip()

PlatformInitialize();

StartupInput input = StartupInput.GetDefault();

// GDI+ ref counts multiple calls to Startup in the same process, so calls from multiple
// domains are ok, just make sure to pair each w/GdiplusShutdown
int status = GdiplusStartup(out s_initToken, ref input, out _);
int status = GdiplusStartup(out s_initToken, StartupInputEx.GetDefault(), out _);
CheckStatus(status);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ private static void PlatformInitialize()

// Imported functions
[GeneratedDllImport(LibraryName)]
internal static partial int GdiplusStartup(out IntPtr token, ref StartupInput input, out StartupOutput output);
internal static partial int GdiplusStartup(out IntPtr token, in StartupInputEx input, out StartupOutput output);

[GeneratedDllImport(LibraryName)]
internal static partial void GdiplusShutdown(ref ulong token);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ private static void PlatformInitialize()

// Imported functions
[GeneratedDllImport(LibraryName)]
private static partial int GdiplusStartup(out IntPtr token, ref StartupInput input, out StartupOutput output);
private static partial int GdiplusStartup(out IntPtr token, in StartupInputEx input, out StartupOutput output);

[GeneratedDllImport(LibraryName)]
internal static partial int GdipCreatePath(int brushMode, out IntPtr path);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3452,9 +3452,9 @@ internal static partial int GdipGetEncoderParameterList(
}

[StructLayout(LayoutKind.Sequential)]
internal struct StartupInput
internal struct StartupInputEx
{
public int GdiplusVersion; // Must be 1
public int GdiplusVersion; // Must be 1 or 2

public IntPtr DebugEventCallback;

Expand All @@ -3463,17 +3463,19 @@ internal struct StartupInput

public Interop.BOOL SuppressExternalCodecs; // FALSE unless you want GDI+ only to use
// its internal image codecs.
public int StartupParameters;

public static StartupInput GetDefault()
public static StartupInputEx GetDefault()
{
OperatingSystem os = Environment.OSVersion;
StartupInput result = default;
StartupInputEx result = default;

// In Windows 7 GDI+1.1 story is different as there are different binaries per GDI+ version.
bool isWindows7 = os.Platform == PlatformID.Win32NT && os.Version.Major == 6 && os.Version.Minor == 1;
result.GdiplusVersion = isWindows7 ? 1 : 2;
result.SuppressBackgroundThread = Interop.BOOL.FALSE;
result.SuppressExternalCodecs = Interop.BOOL.FALSE;
result.StartupParameters = 0;
return result;
}
}
Expand Down