The win32 debugger shows the class name in question in the inspector window that means the information must be available, it's only in question wether the microsoft developers made the function public.
For Debug/Diagnostic/development purpose i wanna write a function to get the instanciated class name of a c++ object as an output and as an input the pointer to the base class.
For example:
const char* GetNameOfInstanciatedClassByBaseClassPtr(class B* pBaseClassOrInstanciatedClass);
class B { public: virtual void Init (){
assert(StringIsEqual(GetNameOfInstanciatedClassByBaseClassPtr(this), "C")); } };
class C : B {} c; c.Init();
So please provide a solution for implementation of function GetNameOfInstanciatedClassByBaseClassPtr.
So question is: Whats the required lib/header/function ? I guess a API for the win32 Debug info would help?
Writing virtual functions which return strings or type_info is not an acceptable solution in my situation.
As i said before: this is for diagnostic/debug/development purpose only, NOT for production code so please avoid discussions about clean code purposes. I could also collect the information manually but since it's about 260 classes i might be faster this way. ;)
EDIT: In the first version of the question i had the function 'GetNameOfInstanciatedClassByBaseClassPtr' called in the constructor of the base class but i observed the information is not yet available in the constructor time. So i put it to an Init method which is always called. In this method the debugger shows the name of the instanciated class so if i put call to the function GetNameOfInstanciatedClassByBaseClassPtr into my init method the information can be obtained. Same seems to be true for the rtti-typeinfo.
EDIT2: As mentioned it may not work for void*, you may need a class B*. However, this can be easily tested. Note some things may be compiler specific. So i adapted the question again.
So the answer i took from the comments is to use either
- Runtime Type Information (rtti) (through native c++) [1]
- Microsoft Debug Interface Access SDK (through COM) [2]
[1] You need to enable this feature in your compiler settings for file or project.
[2] That is the more complex solution.