Need some help with GetPrinterDevice

Thomas Stockbruegger
Thomas Stockbruegger used Ask the Experts™
on
Hello,
I would like to change the call to  GetPrinterDevice like this  
if (GetPrinterDevice(_T("7-PDF Printer"), &hDevNames, &hDevMode))

to a string, but this will not work
if (GetPrinterDevice (PDF_DRUCKER), &hDevNames, &hDevMode))

      
      

       CString str_PDF="7-PDF Printer";

        LPTSTR string = new TCHAR[str_PDF.GetLength()+1];
       _tcscpy(string,str_PDF);
       strcpy(PDF_DRUCKER,string);
 
       if (GetPrinterDevice (PDF_DRUCKER), &hDevNames, &hDevMode))

please let me know
500 points with a solution.
Thank you.
Best regards,
Thomas
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Hi tsp2002,

is this the real code you use? I ask because what's obviously wrong is the ')' after PDF_DRUCKER.

IMO this should work:
     CString str_PDF=_T( "7-PDF Printer" );

       if (GetPrinterDevice (str_PDF, &hDevNames, &hDevMode))

Open in new window

Hope that helps,

ZOPPO
Top Expert 2016
Commented:
 if (GetPrinterDevice (str_PDF.GetBuffer(str_PDF.GetLength()+1), &hDevNames, &hDevMode))

Open in new window


should work.

CString has a built-in operator LPCTSTR which would turn the CString to a (const) pointer to TCHAR. but i assume the GetPrinterDevice uses a LPTSTR for first argument what is a non-const pointer to TCHAR. so you have to use the GetBuffer function.

Sara
thank you, that was very fast
best regards,
Thomas
This will work, and you have to use GetBuffer()

CString str_PDF=_T( "7-PDF Printer" );
if (GetPrinterDevice (str_PDF.GetBuffer(str_PDF.GetLength()+1), &hDevNames, &hDevMode))

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial