Please help me fix this conversion problem
I have some 'legacy' code (viz., someone else's code that I really don't understand very well) that requires the following conversion:
Code:
unsigned short *ucPtr; // Temporary name holder
ucPtr = L"quit"; // error C2440: '=' : cannot convert from 'wchar_t [5]' to 'unsigned short *'
The code was probably written for an earlier compiler, say VC6.0. It gives the above noted error using VC7.0.
What's the problem here ?
Thanks.
Mike
Re: Please help me fix this conversion problem
try TCHAR * instead of unsigned short *
try T("") instead of L""
Re: Please help me fix this conversion problem
Well you're right - it does compile in VC++ 6. I assume that "quit" is intended to be a simple (2 byte) Unicode string (hence the name 'ucPtr') ??
ucPtr will point to the first letter of the string literal "quit". Therefore ++ucPtr would point to 'u' (expressed as 2 bytes). A further ++ucPtr would point to 'i' expressed as 2 bytes, etc.
Re: Please help me fix this conversion problem
TCHAR works - in that it will compile in VC 7.0. But that's only part of the problem. The ucPtr is subsequently given as a parameter to a COLEVARIANT method and the uPtr compiled as TCHAR is rejected by the method as the usual .. cannot convert .
Any other ideas ?
Mike
Re: Please help me fix this conversion problem
Quote:
Originally Posted by Mike Pliam
TCHAR works - in that it will compile in VC 7.0. But that's only part of the problem. The ucPtr is subsequently given as a parameter to a COLEVARIANT method and the uPtr compiled as TCHAR is rejected by the method as the usual .. cannot convert .
Any other ideas ?
Mike
Use the CComVariant or _variant_t classes. They both have constructors that take a TCHAR.
Re: Please help me fix this conversion problem
Try this - Delete the /Zc:wchar_t compiler option in your project settings. Then see if it compiles with original unsigned short* and if your other problems go away. Please let us know what you find out.
Re: Please help me fix this conversion problem
Thanks UnderDog -
That completely solves the problem.
Mike :wave: