E
Eric Eggermann
Hello,
I need to implement a custom print dialog, and I'm trying to show a printers
configuration box, like when you click Properties on the windows forms
PrintDialog. I've gotten as far as showing the dialog. Now what do I do with
the devmode pointer? I've tried using SetHdevmode on the printer setting,
and it's default page setting, but I'm getting a System.EngineExecution
error.
Here's the declarations,
[DllImport("winspool.drv", EntryPoint="DocumentProperties",
SetLastError=true,
CallingConvention=CallingConvention.StdCall)]
private static extern int DocumentProperties(IntPtr hwnd, int hPrinter,
string pDeviceName, IntPtr pDevModeOutput, IntPtr pDevModeInput, int fMode);
[DllImport("winspool.drv", EntryPoint="OpenPrinter", SetLastError=true,
CallingConvention=CallingConvention.StdCall)]
private static extern int OpenPrinter(string pPrinterName, ref int
phPrinter, PRINTER_DEFAULTS pDefault);
[DllImport("winspool.drv", EntryPoint="ClosePrinter", SetLastError=true,
CallingConvention=CallingConvention.StdCall)]
private static extern int ClosePrinter(int hPrinter);
Here's the code to show the dialog:
string printerName = cboPrinter.PrinterName; // user selected printer
PRINTER_DEFAULTS pd = new PRINTER_DEFAULTS();
int handle = 0;
int ret = OpenPrinter(printerName, ref handle, pd);
IntPtr devOut = cboPrinter.Printer.GetHdevmode();
IntPtr devIn = cboPrinter.Printer.GetHdevmode();
int propSetRet = DocumentProperties(this.Handle, handle, printerName,
devOut, devIn, DM_IN_PROMPT | DM_OUT_BUFFER);
int closeRet = ClosePrinter(handle);
cboPrinter.Printer.DefaultPageSettings.SetHdevmode(devOut); //<-- Error here
cboPrinter.Printer.SetHdevmode(devOut);
All the API calls return 1 so that part seems to be working. So how do I
make use of the changes the user made in the printer's dialog? And is there
any way I can use the IntPtr to devOut and get a structure that I can look
at the values? I don't think I really need that for my program, but it might
help me debug.
TIA,
Eric Eggermann
I need to implement a custom print dialog, and I'm trying to show a printers
configuration box, like when you click Properties on the windows forms
PrintDialog. I've gotten as far as showing the dialog. Now what do I do with
the devmode pointer? I've tried using SetHdevmode on the printer setting,
and it's default page setting, but I'm getting a System.EngineExecution
error.
Here's the declarations,
[DllImport("winspool.drv", EntryPoint="DocumentProperties",
SetLastError=true,
CallingConvention=CallingConvention.StdCall)]
private static extern int DocumentProperties(IntPtr hwnd, int hPrinter,
string pDeviceName, IntPtr pDevModeOutput, IntPtr pDevModeInput, int fMode);
[DllImport("winspool.drv", EntryPoint="OpenPrinter", SetLastError=true,
CallingConvention=CallingConvention.StdCall)]
private static extern int OpenPrinter(string pPrinterName, ref int
phPrinter, PRINTER_DEFAULTS pDefault);
[DllImport("winspool.drv", EntryPoint="ClosePrinter", SetLastError=true,
CallingConvention=CallingConvention.StdCall)]
private static extern int ClosePrinter(int hPrinter);
Here's the code to show the dialog:
string printerName = cboPrinter.PrinterName; // user selected printer
PRINTER_DEFAULTS pd = new PRINTER_DEFAULTS();
int handle = 0;
int ret = OpenPrinter(printerName, ref handle, pd);
IntPtr devOut = cboPrinter.Printer.GetHdevmode();
IntPtr devIn = cboPrinter.Printer.GetHdevmode();
int propSetRet = DocumentProperties(this.Handle, handle, printerName,
devOut, devIn, DM_IN_PROMPT | DM_OUT_BUFFER);
int closeRet = ClosePrinter(handle);
cboPrinter.Printer.DefaultPageSettings.SetHdevmode(devOut); //<-- Error here
cboPrinter.Printer.SetHdevmode(devOut);
All the API calls return 1 so that part seems to be working. So how do I
make use of the changes the user made in the printer's dialog? And is there
any way I can use the IntPtr to devOut and get a structure that I can look
at the values? I don't think I really need that for my program, but it might
help me debug.
TIA,
Eric Eggermann