[C++] Setting Printer to Duplex


The Boss
2 Dec 2001
I am trying to put together a program which will change the settings of a printer to Duplex Printing (Printing on both sides).

Here is the code I am using:
   char PortName[256]    = {0};
   char DriverName[256]  = {0};
   char PrinterName[256] = {0};

   HANDLE hDevMode;
   LPDEVMODE pDevMode;

   // Lets load up all the printers into a ComboxBox so we can see them
   ListBox1->Items = Printer()->Printers;

   //Now lets go through them all and make the changes.
   for(int i = 0; i < ListBox1->Items->Count; i++)
     Printer()->PrinterIndex = i;
     Printer()->GetPrinter( PrinterName, DriverName, PortName, (unsigned int)hDevMode );
     if( hDevMode )
        String PrtName = PrinterName;

        // cast to a LPDEVMODE not PDEVMODE
        pDevMode = (LPDEVMODE) GlobalLock( hDevMode );
        if( pDevMode )
           if( pDevMode->dmFields & DM_DUPLEX )
             pDevMode->dmDuplex = DMDUP_HORIZONTAL;
              ShowMessage("Duplex Detected");
             ShowMessage("Not Duplex");

            GlobalUnlock( hDevMode );
         Printer()->SetPrinter(PrinterName, DriverName, PortName, (unsigned int)hDevMode);
    }//loop end

Now I've run this code, and it does change the dmDuplex to DMDUP_HORIZONTAL successfully, however when you go to print it does not print duplex.

In addition to this, if I manually change the printer settings to print Duplex from the Printer Settings Dialog box you get in something like word, and then check the value of dmDuplex I find that it is unchanged, i.e. if it was DMDUP_SIMPLEX and I set it to Duplex printing in the dialog box, it will remain as DMDUP_SIMPLEX.

Now, I am not sure what I am doing wrong. Do I need to update something once I have made the changes to DMDUP_HORIZONTAL so it will refresh it? Or am I barking up the wrong tree - do I need to look somewhere else?

Would be v. grateful if someone can anyone shed some light on this. Thank you.


Members online

No members online now.

Latest profile posts

hello peeps... is been some time since i last came here.
Electronic Punk wrote on Sazar's profile.
Rest in peace my friend, been trying to find you and finally did in the worst way imaginable.
Terrahertz wrote on Electronic Punk's profile.
Yo fellas!
Electronic Punk wrote on Sazar's profile.
Where are you buddy?
Perris Calderon wrote on Electronic Punk's profile.
Hey EP! All good with me, applying for Microsoft MVP right now, should have done this a while ago.

Notifications don't work, I only found your response by coming back to hunt up some threads, if you want, give me your email address so we can keep in touch easier!

Forum statistics

Latest member