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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. how to convert string to resource ID

how to convert string to resource ID

Scheduled Pinned Locked Moved C / C++ / MFC
helptutorialquestionlearning
21 Posts 7 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.
  • L Lost User

    You can also use strings rather than integers to refer to your resource items. If you do not give resource names a #define value, then you can refer to them by the name as string value, rather than its integer equivalent.

    R Offline
    R Offline
    ronovice
    wrote on last edited by
    #12

    i dont't want to use #define because i use stringtables for different languages. a map seems to fit to my needs.

    L 1 Reply Last reply
    0
    • C cmk

      Not possible. IDS_VALUE is a #define, these are resolved by the preprocessor and are not preserved as strings anywhere in the object files.

      ...cmk The idea that I can be presented with a problem, set out to logically solve it with the tools at hand, and wind up with a program that could not be legally used because someone else followed the same logical steps some years ago and filed for a patent on it is horrifying. - John Carmack

      R Offline
      R Offline
      ronovice
      wrote on last edited by
      #13

      thanks! it was worth a try! i will use a map (as the best idea for the moment)!

      1 Reply Last reply
      0
      • R ronovice

        i dont't want to use #define because i use stringtables for different languages. a map seems to fit to my needs.

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

        ronovice wrote:

        i dont't want to use #define

        That is what I was trying to explain in my previous post. If you do not use #define then the resource names can be accessed by their actual name as extracted from your XML, no need for a map or any other type of transform.

        R 1 Reply Last reply
        0
        • C cmk

          Not possible. IDS_VALUE is a #define, these are resolved by the preprocessor and are not preserved as strings anywhere in the object files.

          ...cmk The idea that I can be presented with a problem, set out to logically solve it with the tools at hand, and wind up with a program that could not be legally used because someone else followed the same logical steps some years ago and filed for a patent on it is horrifying. - John Carmack

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

          cmk wrote:

          Not possible.

          Untrue; if you do not equate a resource name to an integer value, then you can address it by the actual string name. [edit]My apologies, this does not hold true for STRINGTABLE entries.[/edit]

          modified on Thursday, January 7, 2010 8:12 AM

          C 1 Reply Last reply
          0
          • L Lost User

            ronovice wrote:

            i dont't want to use #define

            That is what I was trying to explain in my previous post. If you do not use #define then the resource names can be accessed by their actual name as extracted from your XML, no need for a map or any other type of transform.

            R Offline
            R Offline
            ronovice
            wrote on last edited by
            #16

            i wanted to use LoadString method which will need as parameter a UINT, but i have only the string . How can I get from resources the text associated with that UINT if i cant convert the string to UINT ID? if there is another solution(even without using LoadString), I will gladly use it.

            L 1 Reply Last reply
            0
            • R ronovice

              i wanted to use LoadString method which will need as parameter a UINT, but i have only the string . How can I get from resources the text associated with that UINT if i cant convert the string to UINT ID? if there is another solution(even without using LoadString), I will gladly use it.

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

              You could try using FindResourceEx()[^] rather than trying to access it directly. This should allow you to use the name as a string and also to select which language you wish the string to be in. [edit]My apologies, this does not hold true for STRINGTABLE entries, although you could possibly use a user defined resource type.[/edit]

              modified on Thursday, January 7, 2010 8:14 AM

              1 Reply Last reply
              0
              • R ronovice

                I have Resource ID (for a stringtable value)in string format. ex ("IDS_VALUE"). How can i convert it into ID format (UINT) to get the the string using LoadString method. If anybody come across the problem .pls let me know the solution. Advance thanks!

                K Offline
                K Offline
                KarstenK
                wrote on last edited by
                #18

                write in the resource file IDS_VALUE "IDS_VALUE" oh my god :doh: :doh: :doh:

                Press F1 for help or google it. Greetings from Germany

                1 Reply Last reply
                0
                • L Lost User

                  cmk wrote:

                  Not possible.

                  Untrue; if you do not equate a resource name to an integer value, then you can address it by the actual string name. [edit]My apologies, this does not hold true for STRINGTABLE entries.[/edit]

                  modified on Thursday, January 7, 2010 8:12 AM

                  C Offline
                  C Offline
                  cmk
                  wrote on last edited by
                  #19

                  Yeah, RT_STRING's screw things up, you can't even FindResource() on them without jumping through hoops. e.g. Given: IDS_STRING as a String Table entry // Fails hnd = FindResource(mod, MAKEINTRESOURCE(IDS_STRING), RT_STRING); // Works id_string = MAKEINTRESOURCE((LOWORD(IDS_STRING)>>4)+1); hnd = FindResource(mod, id_string, RT_STRING); ... let alone getting the size, or loading the string without using LoadString().

                  ...cmk The idea that I can be presented with a problem, set out to logically solve it with the tools at hand, and wind up with a program that could not be legally used because someone else followed the same logical steps some years ago and filed for a patent on it is horrifying. - John Carmack

                  R L 2 Replies Last reply
                  0
                  • C cmk

                    Yeah, RT_STRING's screw things up, you can't even FindResource() on them without jumping through hoops. e.g. Given: IDS_STRING as a String Table entry // Fails hnd = FindResource(mod, MAKEINTRESOURCE(IDS_STRING), RT_STRING); // Works id_string = MAKEINTRESOURCE((LOWORD(IDS_STRING)>>4)+1); hnd = FindResource(mod, id_string, RT_STRING); ... let alone getting the size, or loading the string without using LoadString().

                    ...cmk The idea that I can be presented with a problem, set out to logically solve it with the tools at hand, and wind up with a program that could not be legally used because someone else followed the same logical steps some years ago and filed for a patent on it is horrifying. - John Carmack

                    R Offline
                    R Offline
                    ronovice
                    wrote on last edited by
                    #20

                    Thanks. i will try this!

                    1 Reply Last reply
                    0
                    • C cmk

                      Yeah, RT_STRING's screw things up, you can't even FindResource() on them without jumping through hoops. e.g. Given: IDS_STRING as a String Table entry // Fails hnd = FindResource(mod, MAKEINTRESOURCE(IDS_STRING), RT_STRING); // Works id_string = MAKEINTRESOURCE((LOWORD(IDS_STRING)>>4)+1); hnd = FindResource(mod, id_string, RT_STRING); ... let alone getting the size, or loading the string without using LoadString().

                      ...cmk The idea that I can be presented with a problem, set out to logically solve it with the tools at hand, and wind up with a program that could not be legally used because someone else followed the same logical steps some years ago and filed for a patent on it is horrifying. - John Carmack

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

                      I really must take my own advice, and test everything before posting suggestions. :mad:

                      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