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 a string to DWORD

Convert a string to DWORD

Scheduled Pinned Locked Moved C / C++ / MFC
tutorialquestion
9 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.
  • I Offline
    I Offline
    Iceberg76
    wrote on last edited by
    #1

    Hello, I am pretty new to Win32 programming. How do I convert a string to a DWORD? For example, I want to convert this value: char *String = "WS_MAXIMIZE"; into a DWORD value. After the conversion, the String should be equal to WindowStyle ( see below ) char *String = "WS_MAXIMIZE"; DWORD WindowStyle = WS_MAXIMIZE; Here are the correct numeric values: String = 0x0046c104 WindowStyle = 16777216 I tried type casting: char *String = "WS_MAXIMIZE"; DWORD WindowStyle = (DWORD)String; But that made WindowStyle = 9093936 and that's not what I want. Please tell me how to convert a string (hexadecimal) to a double word. Thank You.

    S R A T 4 Replies Last reply
    0
    • I Iceberg76

      Hello, I am pretty new to Win32 programming. How do I convert a string to a DWORD? For example, I want to convert this value: char *String = "WS_MAXIMIZE"; into a DWORD value. After the conversion, the String should be equal to WindowStyle ( see below ) char *String = "WS_MAXIMIZE"; DWORD WindowStyle = WS_MAXIMIZE; Here are the correct numeric values: String = 0x0046c104 WindowStyle = 16777216 I tried type casting: char *String = "WS_MAXIMIZE"; DWORD WindowStyle = (DWORD)String; But that made WindowStyle = 9093936 and that's not what I want. Please tell me how to convert a string (hexadecimal) to a double word. Thank You.

      S Offline
      S Offline
      shiraztk
      wrote on last edited by
      #2

      Hi atol converts a string to a double. char *String="16777216"; DWORD num=atol(String); I dont think you will be able to convert "WS_MAXIMIZE" to the appropriate number anyway. WS_MAXIMIZE is a macro and macros within "" are not replaced. Regards The Best Relligion is Science. Once you understand it, you will know God.

      1 Reply Last reply
      0
      • I Iceberg76

        Hello, I am pretty new to Win32 programming. How do I convert a string to a DWORD? For example, I want to convert this value: char *String = "WS_MAXIMIZE"; into a DWORD value. After the conversion, the String should be equal to WindowStyle ( see below ) char *String = "WS_MAXIMIZE"; DWORD WindowStyle = WS_MAXIMIZE; Here are the correct numeric values: String = 0x0046c104 WindowStyle = 16777216 I tried type casting: char *String = "WS_MAXIMIZE"; DWORD WindowStyle = (DWORD)String; But that made WindowStyle = 9093936 and that's not what I want. Please tell me how to convert a string (hexadecimal) to a double word. Thank You.

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

        What are you trying to achieve ? I can't see any point in Iceberg76 wrote: char *String = "WS_MAXIMIZE"; Are you storing some data in a CListCtrl or TreeCtrl ? Or playing with the registry ? ~RaGE();

        1 Reply Last reply
        0
        • I Iceberg76

          Hello, I am pretty new to Win32 programming. How do I convert a string to a DWORD? For example, I want to convert this value: char *String = "WS_MAXIMIZE"; into a DWORD value. After the conversion, the String should be equal to WindowStyle ( see below ) char *String = "WS_MAXIMIZE"; DWORD WindowStyle = WS_MAXIMIZE; Here are the correct numeric values: String = 0x0046c104 WindowStyle = 16777216 I tried type casting: char *String = "WS_MAXIMIZE"; DWORD WindowStyle = (DWORD)String; But that made WindowStyle = 9093936 and that's not what I want. Please tell me how to convert a string (hexadecimal) to a double word. Thank You.

          A Offline
          A Offline
          Alexander M
          wrote on last edited by
          #4

          WM_MAXIMIZE is a MACRO!!!! Only the compiler can convert it to the number it stands for. Convert a string run-time to the value the software has to know the value. you could build an array to map these macro strings to their appropriate number. Don't try it, just do it! ;-)

          I 2 Replies Last reply
          0
          • A Alexander M

            WM_MAXIMIZE is a MACRO!!!! Only the compiler can convert it to the number it stands for. Convert a string run-time to the value the software has to know the value. you could build an array to map these macro strings to their appropriate number. Don't try it, just do it! ;-)

            I Offline
            I Offline
            Iceberg76
            wrote on last edited by
            #5

            Well I have a configuration text file that I read in when the app starts. I am using it so I can make easy changes without recompiling and to give to other developers so they can configure the display the way they want to... So I guess that's what I have to do since they are macros, huh? I'll just read the strings and compare them to an array of known macros and if they are the same I will set them accordingly. Any other suggestions or ideas will be appreciated. Thanks

            1 Reply Last reply
            0
            • I Iceberg76

              Hello, I am pretty new to Win32 programming. How do I convert a string to a DWORD? For example, I want to convert this value: char *String = "WS_MAXIMIZE"; into a DWORD value. After the conversion, the String should be equal to WindowStyle ( see below ) char *String = "WS_MAXIMIZE"; DWORD WindowStyle = WS_MAXIMIZE; Here are the correct numeric values: String = 0x0046c104 WindowStyle = 16777216 I tried type casting: char *String = "WS_MAXIMIZE"; DWORD WindowStyle = (DWORD)String; But that made WindowStyle = 9093936 and that's not what I want. Please tell me how to convert a string (hexadecimal) to a double word. Thank You.

              T Offline
              T Offline
              ThatsAlok
              wrote on last edited by
              #6

              Hi Buddie, I think you have to go for Comparison for performing above task. like this way char *String = "WS_MAXIMIZE"; DWORD WindowStyle; if(strcmp(String ,"WS_MAXIMIZE")==0) WindowStyle = WS_MAXIMIZE; May be that would be right approach for solving this tyoe of problem. ----------------------------- "I Think It Will Help" ----------------------------- Alok Gupta visit me at http://www.thisisalok.tk

              I 1 Reply Last reply
              0
              • T ThatsAlok

                Hi Buddie, I think you have to go for Comparison for performing above task. like this way char *String = "WS_MAXIMIZE"; DWORD WindowStyle; if(strcmp(String ,"WS_MAXIMIZE")==0) WindowStyle = WS_MAXIMIZE; May be that would be right approach for solving this tyoe of problem. ----------------------------- "I Think It Will Help" ----------------------------- Alok Gupta visit me at http://www.thisisalok.tk

                I Offline
                I Offline
                Iceberg76
                wrote on last edited by
                #7

                Thank You!

                T 1 Reply Last reply
                0
                • A Alexander M

                  WM_MAXIMIZE is a MACRO!!!! Only the compiler can convert it to the number it stands for. Convert a string run-time to the value the software has to know the value. you could build an array to map these macro strings to their appropriate number. Don't try it, just do it! ;-)

                  I Offline
                  I Offline
                  Iceberg76
                  wrote on last edited by
                  #8

                  Despite the fact that WM_MAXIMIZE is a macro... If I set: DWORD test = 30343168; then the numerical value works the same with CreateWindow() as when I use: test = WS_MAXIMIZE|WS_OVERLAPPEDWINDOW; Is there no way to compute this numerical value without a compiler? Is this hex converted to binary then to numeric form?

                  1 Reply Last reply
                  0
                  • I Iceberg76

                    Thank You!

                    T Offline
                    T Offline
                    ThatsAlok
                    wrote on last edited by
                    #9

                    Iceberg76 wrote: Thank You! it very nice Hear Thanks :) ----------------------------- "I Think It Will Help" ----------------------------- Alok Gupta visit me at http://www.thisisalok.tk

                    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