Upgrading to Visual Studio 2005 - Part 2

In Visual Studio 2005 C++, functions that previously took a variable declared as const no longer do so.  For example, the following compiles using Visual Studio 2003:

const __wchar_t __pin *strPrinterName = ::PtrToStringChars(printerName);

BOOL result = ::OpenPrinter(strPrinterName, mJobHandle, NULL);

But, with Visual Studio 2005 results in:

error C2664: 'OpenPrinterW' : cannot convert parameter 1 from 'const wchar_t __pin *' to 'LPWSTR'
Conversion loses qualifiers

To get around this, you need to explicitly cast away the const-ness:

const __wchar_t __pin *strPrinterName = ::PtrToStringChars(printerName);

BOOL result = ::OpenPrinter((LPWSTR) strPrinterName, mJobHandle, NULL);

Removing const from the first line won't help because PtrToStringChars is declared as returning a const.

Print | posted @ Sunday, October 01, 2006 9:32 AM

Comments on this entry:

No comments posted yet.

Your comment:

Title:
Name:
Email:
Website:
 
Italic Underline Blockquote Hyperlink
 
 
Please add 5 and 2 and type the answer here: