title: Weird error printing PrintDocument object in .NET
body: <p>I have a Winforms application that generates its own PrintDocument object for printing. It works fine in XP and Windows 7 with my own testing, but one user has been getting the following exception in Vista when they select the print command with an open document:</p>
  
  <pre><code>************** Exception Text **************
  System.ArgumentException: Handle 0 is not valid.
     at System.Drawing.Printing.PrinterSettings.SetHdevmode(IntPtr hdevmode)
     at System.Windows.Forms.PrintDialog.UpdatePrinterSettings(IntPtr hDevMode, IntPtr hDevNames, Int16 copies, Int32 flags, PrinterSettings settings, PageSettings pageSettings)
     at System.Windows.Forms.PrintDialog.ShowPrintDialog(IntPtr hwndOwner, WndProc hookProcPtr, PRINTDLG data)
     at System.Windows.Forms.PrintDialog.RunDialog(IntPtr hwndOwner)
     at System.Windows.Forms.CommonDialog.ShowDialog(IWin32Window owner)
     at System.Windows.Forms.CommonDialog.ShowDialog()
     at Deck_Studio.DSMain.PrintDeck(Object sender, EventArgs e)
     at System.Windows.Forms.MenuItem.OnClick(EventArgs e)
     at System.Windows.Forms.MenuItem.MenuItemData.Execute()
     at System.Windows.Forms.Command.Invoke()
     at System.Windows.Forms.Command.DispatchID(Int32 id)
     at System.Windows.Forms.Control.WmCommand(Message&amp; m)
     at System.Windows.Forms.Control.WndProc(Message&amp; m)
     at System.Windows.Forms.ScrollableControl.WndProc(Message&amp; m)
     at System.Windows.Forms.ContainerControl.WndProc(Message&amp; m)
     at System.Windows.Forms.Form.WndProc(Message&amp; m)
     at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message&amp; m)
     at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message&amp; m)
     at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
  </code></pre>
  
  <p>I'm having a hard time piecing out the nature of this error and any potential ways of duplicating this. The manifest on the executable is in the "limited" permissions mode and even having the user run the application as an administrator generates the error.</p>