|
-
October 6th, 2007, 02:27 PM
#1
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
mpliam
-
October 6th, 2007, 04:22 PM
#2
Re: Please help me fix this conversion problem
try TCHAR * instead of unsigned short *
try T("") instead of L""
If my post was interesting or helpful, perhaps you would consider clicking the 'rate this post' to let me know (middle icon of the group in the upper right of the post).
-
October 6th, 2007, 04:30 PM
#3
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.
"A problem well stated is a problem half solved.” - Charles F. Kettering
-
October 8th, 2007, 05:56 PM
#4
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
mpliam
-
October 8th, 2007, 06:50 PM
#5
Re: Please help me fix this conversion problem
 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.
-
October 9th, 2007, 05:14 AM
#6
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.
Say no to supplying ready made code for homework/work assignments!!
Please rate this post!
-
October 9th, 2007, 12:53 PM
#7
Re: Please help me fix this conversion problem
Thanks UnderDog -
That completely solves the problem.
Mike
mpliam
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|