CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7
  1. #1
    Join Date
    May 2002
    Posts
    1,798

    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

  2. #2
    Join Date
    Nov 2006
    Posts
    1,611

    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).

  3. #3
    John E is offline Elite Member Power Poster
    Join Date
    Apr 2001
    Location
    Manchester, England
    Posts
    4,867

    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

  4. #4
    Join Date
    May 2002
    Posts
    1,798

    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

  5. #5
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    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.

  6. #6
    Join Date
    Jun 2004
    Location
    India
    Posts
    432

    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!

  7. #7
    Join Date
    May 2002
    Posts
    1,798

    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
  •  





Click Here to Expand Forum to Full Width

Featured