Need some help with GetPrinterDevice

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
Thomas StockbrueggerAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

ZoppoCommented:
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
sarabandeCommented:
 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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Thomas StockbrueggerAuthor Commented:
thank you, that was very fast
best regards,
Thomas
Thomas StockbrueggerAuthor Commented:
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))
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual C++.NET

From novice to tech pro — start learning today.