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

fix: PrintDialog not shown #2851

Merged
merged 2 commits into from
Mar 4, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
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
4 changes: 3 additions & 1 deletion Directory.Build.targets
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@
</PropertyGroup>

<PropertyGroup Condition="'$(IsTestProject)' == 'true'">
<TestArchitectures>x64;x86</TestArchitectures>
<Platforms Condition="'$(Platform)' == 'x86'">AnyCPU;x86</Platforms>
<TestArchitectures Condition="'$(Platform)' == 'x86'">x86</TestArchitectures>
<TestArchitectures Condition="'$(Platform)' != 'x86'">x64;x86</TestArchitectures>
</PropertyGroup>

<Target Name="InstrumentModulesNoBuild" BeforeTargets="RunTests" Condition="'$(IsUnitTestProject)' == 'true'">
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using System;
using System.Runtime.InteropServices;

internal partial class Interop
{
internal partial class Comdlg32
{
[DllImport(ExternDll.Comdlg32, ExactSpelling = true, SetLastError = true, CharSet = CharSet.Unicode)]
private static extern BOOL PrintDlgW(ref PRINTDLGW_32 lppd);

[DllImport(ExternDll.Comdlg32, ExactSpelling = true, SetLastError = true, CharSet = CharSet.Unicode)]
private static extern BOOL PrintDlgW(ref PRINTDLGW_64 lppd);

public static BOOL PrintDlg(ref PRINTDLGW lppd)
{
if (IntPtr.Size == 4)
{
if (lppd is PRINTDLGW_32 lppd32)
{
BOOL result = PrintDlgW(ref lppd32);
lppd = lppd32;
return result;
}

throw new InvalidOperationException($"Expected {nameof(PRINTDLGW_32)} data struct");
}

if (lppd is PRINTDLGW_64 lppd64)
{
BOOL result = PrintDlgW(ref lppd64);
lppd = lppd64;
return result;
}

throw new InvalidOperationException($"Expected {nameof(PRINTDLGW_64)} data struct");
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using System;
using System.Runtime.InteropServices;
using static Interop.User32;

internal partial class Interop
{
internal partial class Comdlg32
{
// Any change in PRINTDLG_32, should also be in PRINTDLG and PRINTDLG_64
// x86 requires EXPLICIT packing of 1.

public unsafe interface PRINTDLGW
{
uint lStructSize { get; set; }

IntPtr hwndOwner { get; set; }
IntPtr hDevMode { get; set; }
IntPtr hDevNames { get; set; }
IntPtr hDC { get; set; }

PD Flags { get; set; }

ushort nFromPage { get; set; }
ushort nToPage { get; set; }
ushort nMinPage { get; set; }
ushort nMaxPage { get; set; }
ushort nCopies { get; set; }

IntPtr hInstance { get; set; }
IntPtr lCustData { get; set; }

IntPtr lpfnPrintHook { get; set; }
IntPtr lpfnSetupHook { get; set; }

char* lpPrintTemplateName { get; set; }
char* lpSetupTemplateName { get; set; }

IntPtr hPrintTemplate { get; set; }
IntPtr hSetupTemplate { get; set; }
}

[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode, Pack = 1)]
public unsafe struct PRINTDLGW_32 : PRINTDLGW
{
public uint _lStructSize;
public IntPtr _hwndOwner;
public IntPtr _hDevMode;
public IntPtr _hDevNames;
public IntPtr _hDC;
public PD _flags;
public ushort _nFromPage;
public ushort _nToPage;
public ushort _nMinPage;
public ushort _nMaxPage;
public ushort _nCopies;
public IntPtr _hInstance;
public IntPtr _lCustData;
public IntPtr _lpfnPrintHook;
public IntPtr _lpfnSetupHook;
public char* _lpPrintTemplateName;
public char* _lpSetupTemplateName;
public IntPtr _hPrintTemplate;
public IntPtr _hSetupTemplate;

public uint lStructSize { get => _lStructSize; set => _lStructSize = value; }
public IntPtr hwndOwner { get => _hwndOwner; set => _hwndOwner = value; }
public IntPtr hDevMode { get => _hDevMode; set => _hDevMode = value; }
public IntPtr hDevNames { get => _hDevNames; set => _hDevNames = value; }
public IntPtr hDC { get => _hDC; set => _hDC = value; }
public PD Flags { get => _flags; set => _flags = value; }
public ushort nFromPage { get => _nFromPage; set => _nFromPage = value; }
public ushort nToPage { get => _nToPage; set => _nToPage = value; }
public ushort nMinPage { get => _nMinPage; set => _nMinPage = value; }
public ushort nMaxPage { get => _nMaxPage; set => _nMaxPage = value; }
public ushort nCopies { get => _nCopies; set => _nCopies = value; }
public IntPtr hInstance { get => _hInstance; set => _hInstance = value; }
public IntPtr lCustData { get => _lCustData; set => _lCustData = value; }
public IntPtr lpfnPrintHook { get => _lpfnPrintHook; set => _lpfnPrintHook = value; }
public IntPtr lpfnSetupHook { get => _lpfnSetupHook; set => _lpfnSetupHook = value; }
public char* lpPrintTemplateName { get => _lpPrintTemplateName; set => _lpPrintTemplateName = value; }
public char* lpSetupTemplateName { get => _lpSetupTemplateName; set => _lpSetupTemplateName = value; }
public IntPtr hPrintTemplate { get => _hPrintTemplate; set => _hPrintTemplate = value; }
public IntPtr hSetupTemplate { get => _hSetupTemplate; set => _hSetupTemplate = value; }
}

[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
public unsafe struct PRINTDLGW_64 : PRINTDLGW
{
public uint _lStructSize;
public IntPtr _hwndOwner;
public IntPtr _hDevMode;
public IntPtr _hDevNames;
public IntPtr _hDC;
public PD _flags;
public ushort _nFromPage;
public ushort _nToPage;
public ushort _nMinPage;
public ushort _nMaxPage;
public ushort _nCopies;
public IntPtr _hInstance;
public IntPtr _lCustData;
public IntPtr _lpfnPrintHook;
public IntPtr _lpfnSetupHook;
public char* _lpPrintTemplateName;
public char* _lpSetupTemplateName;
public IntPtr _hPrintTemplate;
public IntPtr _hSetupTemplate;

public uint lStructSize { get => _lStructSize; set => _lStructSize = value; }
public IntPtr hwndOwner { get => _hwndOwner; set => _hwndOwner = value; }
public IntPtr hDevMode { get => _hDevMode; set => _hDevMode = value; }
public IntPtr hDevNames { get => _hDevNames; set => _hDevNames = value; }
public IntPtr hDC { get => _hDC; set => _hDC = value; }
public PD Flags { get => _flags; set => _flags = value; }
public ushort nFromPage { get => _nFromPage; set => _nFromPage = value; }
public ushort nToPage { get => _nToPage; set => _nToPage = value; }
public ushort nMinPage { get => _nMinPage; set => _nMinPage = value; }
public ushort nMaxPage { get => _nMaxPage; set => _nMaxPage = value; }
public ushort nCopies { get => _nCopies; set => _nCopies = value; }
public IntPtr hInstance { get => _hInstance; set => _hInstance = value; }
public IntPtr lCustData { get => _lCustData; set => _lCustData = value; }
public IntPtr lpfnPrintHook { get => _lpfnPrintHook; set => _lpfnPrintHook = value; }
public IntPtr lpfnSetupHook { get => _lpfnSetupHook; set => _lpfnSetupHook = value; }
public char* lpPrintTemplateName { get => _lpPrintTemplateName; set => _lpPrintTemplateName = value; }
public char* lpSetupTemplateName { get => _lpSetupTemplateName; set => _lpSetupTemplateName = value; }
public IntPtr hPrintTemplate { get => _hPrintTemplate; set => _hPrintTemplate = value; }
public IntPtr hSetupTemplate { get => _hSetupTemplate; set => _hSetupTemplate = value; }
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -210,153 +210,6 @@ public class EDITSTREAM64

public delegate int TreeViewCompareCallback(IntPtr lParam1, IntPtr lParam2, IntPtr lParamSort);

// Any change in PRINTDLG, should also be in PRINTDLG_32 and PRINTDLG_64
public interface PRINTDLG
{
int lStructSize { get; set; }

IntPtr hwndOwner { get; set; }
IntPtr hDevMode { get; set; }
IntPtr hDevNames { get; set; }
IntPtr hDC { get; set; }

Comdlg32.PD Flags { get; set; }

short nFromPage { get; set; }
short nToPage { get; set; }
short nMinPage { get; set; }
short nMaxPage { get; set; }
short nCopies { get; set; }

IntPtr hInstance { get; set; }
IntPtr lCustData { get; set; }

WndProc lpfnPrintHook { get; set; }
WndProc lpfnSetupHook { get; set; }

string lpPrintTemplateName { get; set; }
string lpSetupTemplateName { get; set; }

IntPtr hPrintTemplate { get; set; }
IntPtr hSetupTemplate { get; set; }
}

// Any change in PRINTDLG_32, should also be in PRINTDLG and PRINTDLG_64
// x86 requires EXPLICIT packing of 1.
[StructLayout(LayoutKind.Sequential, Pack = 1, CharSet = CharSet.Auto)]
public class PRINTDLG_32 : PRINTDLG
{
int m_lStructSize;

IntPtr m_hwndOwner;
IntPtr m_hDevMode;
IntPtr m_hDevNames;
IntPtr m_hDC;

short m_nFromPage;
short m_nToPage;
short m_nMinPage;
short m_nMaxPage;
short m_nCopies;

IntPtr m_hInstance;
IntPtr m_lCustData;

WndProc m_lpfnPrintHook;
WndProc m_lpfnSetupHook;

string m_lpPrintTemplateName;
string m_lpSetupTemplateName;

IntPtr m_hPrintTemplate;
IntPtr m_hSetupTemplate;

public int lStructSize { get { return m_lStructSize; } set { m_lStructSize = value; } }

public IntPtr hwndOwner { get { return m_hwndOwner; } set { m_hwndOwner = value; } }
public IntPtr hDevMode { get { return m_hDevMode; } set { m_hDevMode = value; } }
public IntPtr hDevNames { get { return m_hDevNames; } set { m_hDevNames = value; } }
public IntPtr hDC { get { return m_hDC; } set { m_hDC = value; } }

public Comdlg32.PD Flags { get; set; }

public short nFromPage { get { return m_nFromPage; } set { m_nFromPage = value; } }
public short nToPage { get { return m_nToPage; } set { m_nToPage = value; } }
public short nMinPage { get { return m_nMinPage; } set { m_nMinPage = value; } }
public short nMaxPage { get { return m_nMaxPage; } set { m_nMaxPage = value; } }
public short nCopies { get { return m_nCopies; } set { m_nCopies = value; } }

public IntPtr hInstance { get { return m_hInstance; } set { m_hInstance = value; } }
public IntPtr lCustData { get { return m_lCustData; } set { m_lCustData = value; } }

public WndProc lpfnPrintHook { get { return m_lpfnPrintHook; } set { m_lpfnPrintHook = value; } }
public WndProc lpfnSetupHook { get { return m_lpfnSetupHook; } set { m_lpfnSetupHook = value; } }

public string lpPrintTemplateName { get { return m_lpPrintTemplateName; } set { m_lpPrintTemplateName = value; } }
public string lpSetupTemplateName { get { return m_lpSetupTemplateName; } set { m_lpSetupTemplateName = value; } }

public IntPtr hPrintTemplate { get { return m_hPrintTemplate; } set { m_hPrintTemplate = value; } }
public IntPtr hSetupTemplate { get { return m_hSetupTemplate; } set { m_hSetupTemplate = value; } }
}

// Any change in PRINTDLG_64, should also be in PRINTDLG_32 and PRINTDLG
// x64 does not require EXPLICIT packing of 1.
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]
public class PRINTDLG_64 : PRINTDLG
{
int m_lStructSize;

IntPtr m_hwndOwner;
IntPtr m_hDevMode;
IntPtr m_hDevNames;
IntPtr m_hDC;

short m_nFromPage;
short m_nToPage;
short m_nMinPage;
short m_nMaxPage;
short m_nCopies;

IntPtr m_hInstance;
IntPtr m_lCustData;

WndProc m_lpfnPrintHook;
WndProc m_lpfnSetupHook;

string m_lpPrintTemplateName;
string m_lpSetupTemplateName;

IntPtr m_hPrintTemplate;
IntPtr m_hSetupTemplate;

public int lStructSize { get { return m_lStructSize; } set { m_lStructSize = value; } }

public IntPtr hwndOwner { get { return m_hwndOwner; } set { m_hwndOwner = value; } }
public IntPtr hDevMode { get { return m_hDevMode; } set { m_hDevMode = value; } }
public IntPtr hDevNames { get { return m_hDevNames; } set { m_hDevNames = value; } }
public IntPtr hDC { get { return m_hDC; } set { m_hDC = value; } }

public Comdlg32.PD Flags { get; set; }

public short nFromPage { get { return m_nFromPage; } set { m_nFromPage = value; } }
public short nToPage { get { return m_nToPage; } set { m_nToPage = value; } }
public short nMinPage { get { return m_nMinPage; } set { m_nMinPage = value; } }
public short nMaxPage { get { return m_nMaxPage; } set { m_nMaxPage = value; } }
public short nCopies { get { return m_nCopies; } set { m_nCopies = value; } }

public IntPtr hInstance { get { return m_hInstance; } set { m_hInstance = value; } }
public IntPtr lCustData { get { return m_lCustData; } set { m_lCustData = value; } }

public WndProc lpfnPrintHook { get { return m_lpfnPrintHook; } set { m_lpfnPrintHook = value; } }
public WndProc lpfnSetupHook { get { return m_lpfnSetupHook; } set { m_lpfnSetupHook = value; } }

public string lpPrintTemplateName { get { return m_lpPrintTemplateName; } set { m_lpPrintTemplateName = value; } }
public string lpSetupTemplateName { get { return m_lpSetupTemplateName; } set { m_lpSetupTemplateName = value; } }

public IntPtr hPrintTemplate { get { return m_hPrintTemplate; } set { m_hPrintTemplate = value; } }
public IntPtr hSetupTemplate { get { return m_hSetupTemplate; } set { m_hSetupTemplate = value; } }
}

[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]
public class PRINTDLGEX
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,32 +18,6 @@ internal static class UnsafeNativeMethods
[DllImport(ExternDll.Kernel32, CharSet = CharSet.Auto)]
public static extern int GetLocaleInfo(uint Locale, int LCType, StringBuilder lpLCData, int cchData);

[DllImport(ExternDll.Comdlg32, EntryPoint = "PrintDlg", SetLastError = true, CharSet = CharSet.Auto)]
public static extern bool PrintDlg_32([In, Out] NativeMethods.PRINTDLG_32 lppd);

[DllImport(ExternDll.Comdlg32, EntryPoint = "PrintDlg", SetLastError = true, CharSet = CharSet.Auto)]
public static extern bool PrintDlg_64([In, Out] NativeMethods.PRINTDLG_64 lppd);

public static bool PrintDlg([In, Out] NativeMethods.PRINTDLG lppd)
{
if (IntPtr.Size == 4)
{
if (!(lppd is NativeMethods.PRINTDLG_32 lppd_32))
{
throw new NullReferenceException("PRINTDLG data is null");
}
return PrintDlg_32(lppd_32);
}
else
{
if (!(lppd is NativeMethods.PRINTDLG_64 lppd_64))
{
throw new NullReferenceException("PRINTDLG data is null");
}
return PrintDlg_64(lppd_64);
}
}

[DllImport(ExternDll.Comdlg32, SetLastError = true, CharSet = CharSet.Auto)]
public static extern HRESULT PrintDlgEx([In, Out] NativeMethods.PRINTDLGEX lppdex);

Expand Down
Loading