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