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. [RESOLVED]: Compile Error during project conversion from VC++6.0 to VC++ 2005 [modified]

[RESOLVED]: Compile Error during project conversion from VC++6.0 to VC++ 2005 [modified]

Scheduled Pinned Locked Moved C / C++ / MFC
helpc++
7 Posts 5 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.
  • P Offline
    P Offline
    Priya_Sundar
    wrote on last edited by
    #1

    Hi all, I have the below code: str.Replace("\r\n", CString((unsigned char)0xB6)); Here i have a CString object 'str' with some string value. It seems '0xB6' stands for line separator or something.. Im not sure.. Well this is the existing code. But when i tried to convert the project to VC++ 2005 i am getting the compile error as: error C2440: '' : cannot convert from 'int' to 'CString'; No constructor could take the source type, or constructor overload resolution was ambiguous. Kindly help to resolve this error. Thanks

    Priya Sundar

    modified on Monday, March 10, 2008 1:03 AM

    T P M 3 Replies Last reply
    0
    • P Priya_Sundar

      Hi all, I have the below code: str.Replace("\r\n", CString((unsigned char)0xB6)); Here i have a CString object 'str' with some string value. It seems '0xB6' stands for line separator or something.. Im not sure.. Well this is the existing code. But when i tried to convert the project to VC++ 2005 i am getting the compile error as: error C2440: '' : cannot convert from 'int' to 'CString'; No constructor could take the source type, or constructor overload resolution was ambiguous. Kindly help to resolve this error. Thanks

      Priya Sundar

      modified on Monday, March 10, 2008 1:03 AM

      T Offline
      T Offline
      toxcct
      wrote on last edited by
      #2

      just try not to enforce into unsigned char :

      str.Replace("\r\n", CString((char)0xB6));

      [VisualCalc][Binary Guide][CommDialogs] | [Forums Guidelines]

      P 1 Reply Last reply
      0
      • T toxcct

        just try not to enforce into unsigned char :

        str.Replace("\r\n", CString((char)0xB6));

        [VisualCalc][Binary Guide][CommDialogs] | [Forums Guidelines]

        P Offline
        P Offline
        Priya_Sundar
        wrote on last edited by
        #3

        Yes it did resolve my error. But now i am getting a warning. "warning C4310: cast truncates constant value" I need to assign a value between 0 - 127 to resolve the warning. But since the val for 0xb6 is 182, will i not be able to eliminate this warning? Any suggestions?

        Priya Sundar

        N 1 Reply Last reply
        0
        • P Priya_Sundar

          Hi all, I have the below code: str.Replace("\r\n", CString((unsigned char)0xB6)); Here i have a CString object 'str' with some string value. It seems '0xB6' stands for line separator or something.. Im not sure.. Well this is the existing code. But when i tried to convert the project to VC++ 2005 i am getting the compile error as: error C2440: '' : cannot convert from 'int' to 'CString'; No constructor could take the source type, or constructor overload resolution was ambiguous. Kindly help to resolve this error. Thanks

          Priya Sundar

          modified on Monday, March 10, 2008 1:03 AM

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

          Try some thing like this,

              CString tempStr;
          tempStr.Format("%d",0xB6);
          str.Replace("\\r\\n", tempStr);
          
          1 Reply Last reply
          0
          • P Priya_Sundar

            Yes it did resolve my error. But now i am getting a warning. "warning C4310: cast truncates constant value" I need to assign a value between 0 - 127 to resolve the warning. But since the val for 0xb6 is 182, will i not be able to eliminate this warning? Any suggestions?

            Priya Sundar

            N Offline
            N Offline
            Nathan Holt at EMOM
            wrote on last edited by
            #5

            Priya_Sundar wrote:

            Yes it did resolve my error. But now i am getting a warning. "warning C4310: cast truncates constant value" I need to assign a value between 0 - 127 to resolve the warning. But since the val for 0xb6 is 182, will i not be able to eliminate this warning? Any suggestions? Priya Sundar

            The actual range of acceptable values should be -128 to 127, and I think 0xB6 maps to -74. However, I think unsigned char is the right type for what you are doing, and CString requiring a signed character poses a problem. You may be able to use a string "\xB6" instead of a character to initialize the CString. Nathan

            1 Reply Last reply
            0
            • P Priya_Sundar

              Hi all, I have the below code: str.Replace("\r\n", CString((unsigned char)0xB6)); Here i have a CString object 'str' with some string value. It seems '0xB6' stands for line separator or something.. Im not sure.. Well this is the existing code. But when i tried to convert the project to VC++ 2005 i am getting the compile error as: error C2440: '' : cannot convert from 'int' to 'CString'; No constructor could take the source type, or constructor overload resolution was ambiguous. Kindly help to resolve this error. Thanks

              Priya Sundar

              modified on Monday, March 10, 2008 1:03 AM

              M Offline
              M Offline
              Mike Dimmick
              wrote on last edited by
              #6

              There are two overloads of CString::Replace: one takes two LPCTSTR parameters while the other takes two TCHAR parameters. When converting to Visual C++ 2005 you normally run into two issues: 1. The default character type is now Unicode; 2. The new compiler is more conformant to the C++ standard Here you have an additional complication that CString has changed significantly (it's now a template, for example). The MFC 6.0 version would have called the CString constructor that takes a TCHAR ch and an integer nRepeat, which was defaulted to 1. This version of the constructor generated a string of nRepeat copies of ch. This still exists in MFC 8.0 but has been marked explicit, which means that the types must match exactly. However, calling a CString constructor is unnecessary - you should instead use a string literal.

              str.Replace( "\r\n", "\xb6" );

              Because of the change to Unicode, you may find you need to put _T() around both string literals.

              DoEvents: Generating unexpected recursion since 1991

              P 1 Reply Last reply
              0
              • M Mike Dimmick

                There are two overloads of CString::Replace: one takes two LPCTSTR parameters while the other takes two TCHAR parameters. When converting to Visual C++ 2005 you normally run into two issues: 1. The default character type is now Unicode; 2. The new compiler is more conformant to the C++ standard Here you have an additional complication that CString has changed significantly (it's now a template, for example). The MFC 6.0 version would have called the CString constructor that takes a TCHAR ch and an integer nRepeat, which was defaulted to 1. This version of the constructor generated a string of nRepeat copies of ch. This still exists in MFC 8.0 but has been marked explicit, which means that the types must match exactly. However, calling a CString constructor is unnecessary - you should instead use a string literal.

                str.Replace( "\r\n", "\xb6" );

                Because of the change to Unicode, you may find you need to put _T() around both string literals.

                DoEvents: Generating unexpected recursion since 1991

                P Offline
                P Offline
                Priya_Sundar
                wrote on last edited by
                #7

                Thankyou very much. My errors are resolved.

                Priya Sundar

                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