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. ATL / WTL / STL
  4. Get struct-members' names in Visual Studio console application?

Get struct-members' names in Visual Studio console application?

Scheduled Pinned Locked Moved ATL / WTL / STL
csharpc++visual-studiohardware
10 Posts 3 Posters 22 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.
  • A Offline
    A Offline
    arnold_w
    wrote on last edited by
    #1

    I need to debug an embedded C-application that contains a lot of the following structs: MyStruct.MySubStruct.MyEnum I have ported the code into a Visual Studio 2005 console application and I would like to dump all the struct-members (several hundred in total) to a text-file like this: MyStruct.MySubStruct.MyEnum = MyEnumValue I know this isn't possible in pure Visual Studio c programming language, but aren't you allowed to include C++ files as well in a Visual Studio console project? If so, is C++ capable of converting struct members and enums into text strings?

    L Richard Andrew x64R 3 Replies Last reply
    0
    • A arnold_w

      I need to debug an embedded C-application that contains a lot of the following structs: MyStruct.MySubStruct.MyEnum I have ported the code into a Visual Studio 2005 console application and I would like to dump all the struct-members (several hundred in total) to a text-file like this: MyStruct.MySubStruct.MyEnum = MyEnumValue I know this isn't possible in pure Visual Studio c programming language, but aren't you allowed to include C++ files as well in a Visual Studio console project? If so, is C++ capable of converting struct members and enums into text strings?

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

      arnold_w wrote:

      pure Visual Studio c programming language

      There is no such thing. And your code above does not make clear what the problem is in sending the struct contents to a text file. Generally speaking you need to write the code to dump each element of the struct. Or you could just run the program in the Visual Studio debugger and examine the fields that way.

      A 2 Replies Last reply
      0
      • L Lost User

        arnold_w wrote:

        pure Visual Studio c programming language

        There is no such thing. And your code above does not make clear what the problem is in sending the struct contents to a text file. Generally speaking you need to write the code to dump each element of the struct. Or you could just run the program in the Visual Studio debugger and examine the fields that way.

        A Offline
        A Offline
        arnold_w
        wrote on last edited by
        #3

        Just like

        __FILE__

        generates a string with file name and

        __LINE__

        generates a string with the line number, I would like to have some way of generating strings with the structs' and members' names.

        L 1 Reply Last reply
        0
        • A arnold_w

          I need to debug an embedded C-application that contains a lot of the following structs: MyStruct.MySubStruct.MyEnum I have ported the code into a Visual Studio 2005 console application and I would like to dump all the struct-members (several hundred in total) to a text-file like this: MyStruct.MySubStruct.MyEnum = MyEnumValue I know this isn't possible in pure Visual Studio c programming language, but aren't you allowed to include C++ files as well in a Visual Studio console project? If so, is C++ capable of converting struct members and enums into text strings?

          Richard Andrew x64R Offline
          Richard Andrew x64R Offline
          Richard Andrew x64
          wrote on last edited by
          #4

          The C and C++ runtime environments do not maintain metadata on the types in your program the way a .NET executable does. Therefore, I don't see how you would dump the type names, unless you develop a program to process your source code and extract the information that way. If I'm wrong about this, I invite correction.

          The difficult we do right away... ...the impossible takes slightly longer.

          1 Reply Last reply
          0
          • A arnold_w

            Just like

            __FILE__

            generates a string with file name and

            __LINE__

            generates a string with the line number, I would like to have some way of generating strings with the structs' and members' names.

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

            Those are compiler defined values, and have nothing to do with your question.

            1 Reply Last reply
            0
            • L Lost User

              arnold_w wrote:

              pure Visual Studio c programming language

              There is no such thing. And your code above does not make clear what the problem is in sending the struct contents to a text file. Generally speaking you need to write the code to dump each element of the struct. Or you could just run the program in the Visual Studio debugger and examine the fields that way.

              A Offline
              A Offline
              arnold_w
              wrote on last edited by
              #6

              I guess I could use the Visual Studio debugger and use OCR (optical character recognition) on the watch window. Can anybody recommend a good, free OCR application?

              L 1 Reply Last reply
              0
              • A arnold_w

                I guess I could use the Visual Studio debugger and use OCR (optical character recognition) on the watch window. Can anybody recommend a good, free OCR application?

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

                arnold_w wrote:

                OCR (optical character recognition) on the watch window

                I'd like to see that work.

                1 Reply Last reply
                0
                • A arnold_w

                  I need to debug an embedded C-application that contains a lot of the following structs: MyStruct.MySubStruct.MyEnum I have ported the code into a Visual Studio 2005 console application and I would like to dump all the struct-members (several hundred in total) to a text-file like this: MyStruct.MySubStruct.MyEnum = MyEnumValue I know this isn't possible in pure Visual Studio c programming language, but aren't you allowed to include C++ files as well in a Visual Studio console project? If so, is C++ capable of converting struct members and enums into text strings?

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

                  Hi, Yes, I had to do this many years ago. However you are not really giving me enough information. You need to be very specific when you ask for help. Do you need to do this on a Release build or Debug build? Do you need to do this at run-time or compile-time? 1.) Preprocessor abuse[^] that stores the variable name in an extra char field in the struct. Here is a partial example[^]. 2.) If you are using C++ there are several boost libs[^] that allow you to implement some reflection. 3.) The Debug Interface Access SDK[^] can be used to get all of the structs and member variable names. If you go this route... you will need to generate a PDB. Best Wishes, -David Delaune

                  A 1 Reply Last reply
                  0
                  • L Lost User

                    Hi, Yes, I had to do this many years ago. However you are not really giving me enough information. You need to be very specific when you ask for help. Do you need to do this on a Release build or Debug build? Do you need to do this at run-time or compile-time? 1.) Preprocessor abuse[^] that stores the variable name in an extra char field in the struct. Here is a partial example[^]. 2.) If you are using C++ there are several boost libs[^] that allow you to implement some reflection. 3.) The Debug Interface Access SDK[^] can be used to get all of the structs and member variable names. If you go this route... you will need to generate a PDB. Best Wishes, -David Delaune

                    A Offline
                    A Offline
                    arnold_w
                    wrote on last edited by
                    #9

                    Since this a debug tool that only will be used in-house, it doesn't matter if I use release or debug and compile time is fine.

                    L 1 Reply Last reply
                    0
                    • A arnold_w

                      Since this a debug tool that only will be used in-house, it doesn't matter if I use release or debug and compile time is fine.

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

                      Hi,

                      arnold_w wrote:

                      Since this a debug tool

                      If this is a debug tool I recommend that you check out the Debug Interface Access SDK[^] which will allow you to get all kinds of useful information and statistics about your executable. You can dump each function/class size and type along with the variable name. Dia2dump Sample[^] TYPEINFODUMP[^] Best Wishes, -David Delaune

                      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