troubleshooting Question

Need some help with CString and LPCSTR

Avatar of Thomas Stockbruegger
Thomas StockbrueggerFlag for Germany asked on
Visual C++.NETC++* MFC
8 Comments2 Solutions179 ViewsLast Modified:
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);


               //--------------------------- Papier Auswahl DEVMODE ----------------------------------
              LPDEVMODE dev=dlgPrint.GetDevMode();
                   dev->dmOrientation=DMORIENT_PORTRAIT;  //Hochformat

I will get this error:
errorThank you for your help,
Best regards,
Kevin Stanush
Lead Developer

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 2 Answers and 8 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 2 Answers and 8 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros