We help IT Professionals succeed at work.
Get Started

Need some help with CString and LPCSTR

167 Views
Last Modified: 2020-02-25
Hello,
I would like to change  the name of the printer into a  string.
This is my code that works:
if (GetPrinterDevice(_T("\\\\DSERVER\\Brother HL-7050 series"), &hDevNames, &hDevMode))


I have tried this one, but it will not work:


void CZahlen_SortierenDlg::OnBnClickedButton1()
{
       HANDLE hDevMode;
     HANDLE hDevNames;

       CString D="\\\\\\\\DSERVER\\\\Brother HL-7050 series";
       LPCSTR drucker=(LPCSTR)(LPCSTR)D;



// if (GetPrinterDevice(_T("\\\\DSERVER\\Brother HL-7050 series"), &hDevNames, &hDevMode))


 
 
   if (GetPrinterDevice(drucker), &hDevNames, &hDevMode)
      
     {
          AfxGetApp()->SelectPrinter(hDevNames, hDevMode);

          CPrintDialog dlgPrint(FALSE,PD_PAGENUMS|PD_USEDEVMODECOPIESANDCOLLATE , this);

               //--------------------------- Papier Auswahl DEVMODE ----------------------------------
          if(AfxGetApp()->GetPrinterDeviceDefaults(&dlgPrint.m_pd))
          {               
              LPDEVMODE dev=dlgPrint.GetDevMode();
                GlobalUnlock(dev);
                            
                   dev->dmOrientation=DMORIENT_PORTRAIT;  //Hochformat
                  dev->dmPaperSize=DMPAPER_A4;
               
                dev->dmCopies=1;  
                dev->dmDefaultSource=DMBIN_AUTO;


I will get this error:
errorThank you for your help,
Best regards,
Thomas
Comment
Watch Question
Lead Developer
CERTIFIED EXPERT
Commented:
This problem has been solved!
Unlock 2 Answers and 8 Comments.
See Answers
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant

An Experts Exchange subscription includes unlimited access to online courses.

Get Started
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE