Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. CString problems from VC++ 6.0 to Visual Studio 2005

CString problems from VC++ 6.0 to Visual Studio 2005

Scheduled Pinned Locked Moved C / C++ / MFC
c++helpcsharpvisual-studioquestion
8 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • G Offline
    G Offline
    GDavy
    wrote on last edited by
    #1

    This is probably a known problem with an easy workaround, but I haven`t seen it yet. The problem is that I want to use code written in Visual C++ 6.0 in Visual Studio 2005. When I compile I get the following errors e.g.: CString temp = pOrder->GetItemNr(); pOrder->GetItemNr() returns a const char* the error I got is: error C2440: 'initializing' : cannot convert from 'const char *' to 'ATL::CStringT' What can I do so that this assignment works again? Anyone got any ideas? Thanks for any help, Davy

    P C 2 Replies Last reply
    0
    • G GDavy

      This is probably a known problem with an easy workaround, but I haven`t seen it yet. The problem is that I want to use code written in Visual C++ 6.0 in Visual Studio 2005. When I compile I get the following errors e.g.: CString temp = pOrder->GetItemNr(); pOrder->GetItemNr() returns a const char* the error I got is: error C2440: 'initializing' : cannot convert from 'const char *' to 'ATL::CStringT' What can I do so that this assignment works again? Anyone got any ideas? Thanks for any help, Davy

      P Offline
      P Offline
      prasad_som
      wrote on last edited by
      #2

      GDavy wrote:

      CString temp = pOrder->GetItemNr();

      Modify this to,

      CString temp = CString(pOrder->GetItemNr());


      Prasad MS MVP -  VC++

      G C 2 Replies Last reply
      0
      • P prasad_som

        GDavy wrote:

        CString temp = pOrder->GetItemNr();

        Modify this to,

        CString temp = CString(pOrder->GetItemNr());


        Prasad MS MVP -  VC++

        G Offline
        G Offline
        GDavy
        wrote on last edited by
        #3

        Isn`t there a better way? In my old code I have a lot of places where a const char* is assigned into a CString sometimes directly sometimes as a parameter in a function. It`s a lot of places to do this. :( Anyway thanks for your answer, I was affraid this might be the only solution...

        1 Reply Last reply
        0
        • G GDavy

          This is probably a known problem with an easy workaround, but I haven`t seen it yet. The problem is that I want to use code written in Visual C++ 6.0 in Visual Studio 2005. When I compile I get the following errors e.g.: CString temp = pOrder->GetItemNr(); pOrder->GetItemNr() returns a const char* the error I got is: error C2440: 'initializing' : cannot convert from 'const char *' to 'ATL::CStringT' What can I do so that this assignment works again? Anyone got any ideas? Thanks for any help, Davy

          C Offline
          C Offline
          cp9876
          wrote on last edited by
          #4

          I certainly use this construct regularly in VS2005 and it works OK for me. What I have just checked is: const char lpszFiles[] = "FileInfo"; CString str = lpszFiles; essentially the same. You haven't got unicode defined have you?

          Peter "Until the invention of the computer, the machine gun was the device that enabled humans to make the most mistakes in the smallest amount of time."

          G 1 Reply Last reply
          0
          • C cp9876

            I certainly use this construct regularly in VS2005 and it works OK for me. What I have just checked is: const char lpszFiles[] = "FileInfo"; CString str = lpszFiles; essentially the same. You haven't got unicode defined have you?

            Peter "Until the invention of the computer, the machine gun was the device that enabled humans to make the most mistakes in the smallest amount of time."

            G Offline
            G Offline
            GDavy
            wrote on last edited by
            #5

            I have actually. It`s necessary because sometimes more than 1 language needs to be displayed. In VC 6.0 the conversion from const char* to WCHAR* used by CString happened automatically, this doesn`t seem to be the case anymore :(

            1 Reply Last reply
            0
            • P prasad_som

              GDavy wrote:

              CString temp = pOrder->GetItemNr();

              Modify this to,

              CString temp = CString(pOrder->GetItemNr());


              Prasad MS MVP -  VC++

              C Offline
              C Offline
              Cedric Moonen
              wrote on last edited by
              #6

              What's the difference ? Both will call the same CString constructor so I don't see why it would work...


              Cédric Moonen Software developer
              Charting control [v1.1]

              G P 2 Replies Last reply
              0
              • C Cedric Moonen

                What's the difference ? Both will call the same CString constructor so I don't see why it would work...


                Cédric Moonen Software developer
                Charting control [v1.1]

                G Offline
                G Offline
                GDavy
                wrote on last edited by
                #7

                That's what I thought too originally, but doing this does make it work (compiler error is gone) So I guess I`ll just have to do this for all the cases in my old code :sigh: . Just came back from easter hollidays and now this mind-numbing job of putting CString () whereever the compiler complains... I need hollidays again :^)

                1 Reply Last reply
                0
                • C Cedric Moonen

                  What's the difference ? Both will call the same CString constructor so I don't see why it would work...


                  Cédric Moonen Software developer
                  Charting control [v1.1]

                  P Offline
                  P Offline
                  prasad_som
                  wrote on last edited by
                  #8

                  Cedric Moonen wrote:

                  Both will call the same CString constructor

                  I thought that way initially. But, some how it is converting char* to wchar_t* in this case.

                  Cedric Moonen wrote:

                  I don't see why it would work...

                  And it is working.


                  Prasad MS MVP -  VC++

                  1 Reply Last reply
                  0
                  Reply
                  • Reply as topic
                  Log in to reply
                  • Oldest to Newest
                  • Newest to Oldest
                  • Most Votes


                  • Login

                  • Don't have an account? Register

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • World
                  • Users
                  • Groups