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. Convert DWORD to CString

Convert DWORD to CString

Scheduled Pinned Locked Moved C / C++ / MFC
11 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.
  • J Offline
    J Offline
    JensB
    wrote on last edited by
    #1

    Hi Need to convert a DWORD to a CString and a CString to a DWORD type. Hope someone knows :) Greetings Jens

    Y R R 5 Replies Last reply
    0
    • J JensB

      Hi Need to convert a DWORD to a CString and a CString to a DWORD type. Hope someone knows :) Greetings Jens

      Y Offline
      Y Offline
      YSRao
      wrote on last edited by
      #2

      Hi, converting a CString into DWORD means, u are going to covert integer to char here is example. #define HELLO 100 DWORD dwrd=HELLO; CString str1; char str[10]; str1=itoa(HELLO,str,10); //CString str1=str; AfxMessageBox(str1); this will convert the DWORD into CString,but it is not wise.You can't get CString value like "HELLO". it is not possible i think.you can get 100 as a CString value. yakkalas

      1 Reply Last reply
      0
      • J JensB

        Hi Need to convert a DWORD to a CString and a CString to a DWORD type. Hope someone knows :) Greetings Jens

        Y Offline
        Y Offline
        YSRao
        wrote on last edited by
        #3

        DWORD is also an unsigned integer,trying to convert it into CString means converting integer to char. Here I am sending simple Ex. DWORD dwrd=HELLO; CString str1; char str[10]; str1=::itoa(HELLO,str,10); //CString str1=str; AfxMessageBox(str1); This simple code will show u 100 not HELLO.So as I am thinking,it is not possible. You mean to try to get CString value as HELLO?:confused: if so it is not possible as per my knowledge. yakkalas.

        1 Reply Last reply
        0
        • J JensB

          Hi Need to convert a DWORD to a CString and a CString to a DWORD type. Hope someone knows :) Greetings Jens

          Y Offline
          Y Offline
          YSRao
          wrote on last edited by
          #4

          DWORD is also an unsigned integer,trying to convert it into CString means converting integer to char. Here I am sending simple Ex. #define HELLO 100 DWORD dwrd=HELLO; CString str1; char str[10]; str1=::itoa(HELLO,str,10); //CString str1=str; AfxMessageBox(str1); This simple code will show u 100 not HELLO.So as I am thinking,it is not possible. You mean to try to get CString value as HELLO?:confused: if so it is not possible as per my knowledge. yakkalas.

          J 1 Reply Last reply
          0
          • J JensB

            Hi Need to convert a DWORD to a CString and a CString to a DWORD type. Hope someone knows :) Greetings Jens

            R Offline
            R Offline
            Rage
            wrote on last edited by
            #5

            DWORD d; CString str; d=3; str.Format("%i",d); str="3"; d=atol(str.operator LPCTSSTR()); If this does not work, have a look at http://www.codeproject.com/cpp/cppforumfaq.asp#cpp_atoi[^] ~RaGE();

            J 1 Reply Last reply
            0
            • Y YSRao

              DWORD is also an unsigned integer,trying to convert it into CString means converting integer to char. Here I am sending simple Ex. #define HELLO 100 DWORD dwrd=HELLO; CString str1; char str[10]; str1=::itoa(HELLO,str,10); //CString str1=str; AfxMessageBox(str1); This simple code will show u 100 not HELLO.So as I am thinking,it is not possible. You mean to try to get CString value as HELLO?:confused: if so it is not possible as per my knowledge. yakkalas.

              J Offline
              J Offline
              JensB
              wrote on last edited by
              #6

              Well, it's like this i wanted: I got a CString strValue = "5"; But i got a function which only accepts DWORD values; so instead of CString strValue = "5"; It need to be converted to: DWORD dvalue = 5; that's all to it actually.

              Y 1 Reply Last reply
              0
              • J JensB

                Well, it's like this i wanted: I got a CString strValue = "5"; But i got a function which only accepts DWORD values; so instead of CString strValue = "5"; It need to be converted to: DWORD dvalue = 5; that's all to it actually.

                Y Offline
                Y Offline
                YSRao
                wrote on last edited by
                #7

                CString strValue="5"; DWORD dValue=atoi(strValue); then dValue contains what is the value in strValue. dValue=5; yakkalas

                1 Reply Last reply
                0
                • R Rage

                  DWORD d; CString str; d=3; str.Format("%i",d); str="3"; d=atol(str.operator LPCTSSTR()); If this does not work, have a look at http://www.codeproject.com/cpp/cppforumfaq.asp#cpp_atoi[^] ~RaGE();

                  J Offline
                  J Offline
                  JensB
                  wrote on last edited by
                  #8

                  ok thanks for your help all. I fixed the problem like this: //CString -> long integer CString strBurnr = m_listbur.GetItemText(1,2); DWORD burnr = atol(strBurnr); //Long Integer -> CString char* szTemp; ltoa(burnr, szTemp,10); CString strTemp; strTemp = (CString) szTemp; Thanks, all works fine. :) and btw (this isn't about conversions: does anyone of you guys know how to put a button in a field (in CListView) at every row?) Greetings Jens

                  D 1 Reply Last reply
                  0
                  • J JensB

                    ok thanks for your help all. I fixed the problem like this: //CString -> long integer CString strBurnr = m_listbur.GetItemText(1,2); DWORD burnr = atol(strBurnr); //Long Integer -> CString char* szTemp; ltoa(burnr, szTemp,10); CString strTemp; strTemp = (CString) szTemp; Thanks, all works fine. :) and btw (this isn't about conversions: does anyone of you guys know how to put a button in a field (in CListView) at every row?) Greetings Jens

                    D Offline
                    D Offline
                    David Crow
                    wrote on last edited by
                    #9

                    JensB wrote: char* szTemp; ltoa(burnr, szTemp,10); This can't work. You've allocated no memory for szTemp. It's just a pointer pointing to who knows where! To get a number, whether its an int, long, etc, into a CString object, just use CString::Format() as in:

                    DWORD dwNumber = 123;
                    CString strTemp;
                    strTemp.Format("%lu", dwNumber);

                    J 1 Reply Last reply
                    0
                    • D David Crow

                      JensB wrote: char* szTemp; ltoa(burnr, szTemp,10); This can't work. You've allocated no memory for szTemp. It's just a pointer pointing to who knows where! To get a number, whether its an int, long, etc, into a CString object, just use CString::Format() as in:

                      DWORD dwNumber = 123;
                      CString strTemp;
                      strTemp.Format("%lu", dwNumber);

                      J Offline
                      J Offline
                      JensB
                      wrote on last edited by
                      #10

                      yeah i'm sorry I made a typo there i had 'char szTemp[10];' here :) Anyway, thanks :)

                      1 Reply Last reply
                      0
                      • J JensB

                        Hi Need to convert a DWORD to a CString and a CString to a DWORD type. Hope someone knows :) Greetings Jens

                        R Offline
                        R Offline
                        Renjith Ramachandran
                        wrote on last edited by
                        #11

                        DWORD-STRING itoa() STRING-DWORD atoi()


                        [ It is possible to represent everything in this universe by using 0 and 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