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. "Converting string retrieved from windows registry to integer"

"Converting string retrieved from windows registry to integer"

Scheduled Pinned Locked Moved C / C++ / MFC
windows-adminhelp
8 Posts 6 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.
  • H Offline
    H Offline
    harsh_2961
    wrote on last edited by
    #1

    hi, i am using Windows registry to store an integer value on closing of my dialog and running the application again i am retrieving this value.. this retrieved as string and i tried using "atoi()" to convert but iis giving following error. "'atoi' : cannot convert parameter 1 from 'CString' to 'const char *'" and the lines while retrieving the string are.. System::String* valueNames[] = keySoftware->GetValueNames(); for( int i = 0; i < valueNames->Length; i++) { CString strValue = static_cast(keySoftware->GetValue(valueNames[i])); .... .... ....

    Harsha

    L N D P 5 Replies Last reply
    0
    • H harsh_2961

      hi, i am using Windows registry to store an integer value on closing of my dialog and running the application again i am retrieving this value.. this retrieved as string and i tried using "atoi()" to convert but iis giving following error. "'atoi' : cannot convert parameter 1 from 'CString' to 'const char *'" and the lines while retrieving the string are.. System::String* valueNames[] = keySoftware->GetValueNames(); for( int i = 0; i < valueNames->Length; i++) { CString strValue = static_cast(keySoftware->GetValue(valueNames[i])); .... .... ....

      Harsha

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      I will let you know i a while:laugh:

      1 Reply Last reply
      0
      • H harsh_2961

        hi, i am using Windows registry to store an integer value on closing of my dialog and running the application again i am retrieving this value.. this retrieved as string and i tried using "atoi()" to convert but iis giving following error. "'atoi' : cannot convert parameter 1 from 'CString' to 'const char *'" and the lines while retrieving the string are.. System::String* valueNames[] = keySoftware->GetValueNames(); for( int i = 0; i < valueNames->Length; i++) { CString strValue = static_cast(keySoftware->GetValue(valueNames[i])); .... .... ....

        Harsha

        N Offline
        N Offline
        Naveen
        wrote on last edited by
        #3

        have you defined _UNICODE in your project settings?

        nave

        1 Reply Last reply
        0
        • H harsh_2961

          hi, i am using Windows registry to store an integer value on closing of my dialog and running the application again i am retrieving this value.. this retrieved as string and i tried using "atoi()" to convert but iis giving following error. "'atoi' : cannot convert parameter 1 from 'CString' to 'const char *'" and the lines while retrieving the string are.. System::String* valueNames[] = keySoftware->GetValueNames(); for( int i = 0; i < valueNames->Length; i++) { CString strValue = static_cast(keySoftware->GetValue(valueNames[i])); .... .... ....

          Harsha

          D Offline
          D Offline
          Don Box
          wrote on last edited by
          #4

          Do this way, Suppose strKey contains the registry value it read.

          int nTemp = atoi (strKey.operator LPCSTR ());

          This will surely work.

          Come online at:- jubinc@skype

          1 Reply Last reply
          0
          • H harsh_2961

            hi, i am using Windows registry to store an integer value on closing of my dialog and running the application again i am retrieving this value.. this retrieved as string and i tried using "atoi()" to convert but iis giving following error. "'atoi' : cannot convert parameter 1 from 'CString' to 'const char *'" and the lines while retrieving the string are.. System::String* valueNames[] = keySoftware->GetValueNames(); for( int i = 0; i < valueNames->Length; i++) { CString strValue = static_cast(keySoftware->GetValue(valueNames[i])); .... .... ....

            Harsha

            D Offline
            D Offline
            Don Box
            wrote on last edited by
            #5

            Do this way, Suppose strKey contains the registry value it read and it is a CString object.

            int nTemp = atoi (strKey.operator LPCSTR ());

            This will surely work.

            Come online at:- jubinc@skype

            H C 2 Replies Last reply
            0
            • D Don Box

              Do this way, Suppose strKey contains the registry value it read and it is a CString object.

              int nTemp = atoi (strKey.operator LPCSTR ());

              This will surely work.

              Come online at:- jubinc@skype

              H Offline
              H Offline
              harsh_2961
              wrote on last edited by
              #6

              Thank you.. i will try this out and let tou know :)

              Harsha

              1 Reply Last reply
              0
              • H harsh_2961

                hi, i am using Windows registry to store an integer value on closing of my dialog and running the application again i am retrieving this value.. this retrieved as string and i tried using "atoi()" to convert but iis giving following error. "'atoi' : cannot convert parameter 1 from 'CString' to 'const char *'" and the lines while retrieving the string are.. System::String* valueNames[] = keySoftware->GetValueNames(); for( int i = 0; i < valueNames->Length; i++) { CString strValue = static_cast(keySoftware->GetValue(valueNames[i])); .... .... ....

                Harsha

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

                i wonder why you needed atol here. If using MC++, then you can use Convert::ToInt32 function for this purpose, instead of mix of all these things.

                System::String* valueNames[] = keySoftware->GetValueNames();
                for( int i = 0; i < valueNames->Length; i++)
                {
                int nValue = Convert::ToInt32(valueNames[i]);
                ...
                }

                And use <pre> tags while posting code.

                Prasad Notifier using ATL | Operator new[],delete[][^]

                1 Reply Last reply
                0
                • D Don Box

                  Do this way, Suppose strKey contains the registry value it read and it is a CString object.

                  int nTemp = atoi (strKey.operator LPCSTR ());

                  This will surely work.

                  Come online at:- jubinc@skype

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

                  Never call an operator this way, this is just uggly. You can simply do that: int nTemp = atoi((LPCSTR)strKey); But I don't think it will work because if the cast was possible it would have been implicitely done already and you wouldn't have an error.


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

                  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