none
Is there a way to display a type using natvis?

    Question

  • In the Watch windows, you can see the type of a variable.  When natvis is in use, it'll show the type of your expression as well, again within the Watch window.

    In the Watch window, if the object was casted to a CObject* and the actual type was, say a CArray<CString, CString&>, the Type column would say CObject* {CArray<CString, CString&>} (actually it would say something like CObject * {CArray<ATL::CStringT<char,StrTraitMFC_DLL<char,ATL::ChTraitsCRT<char> > >,ATL::CStringT<char,StrTraitMFC_DLL<char,ATL::ChTraitsCRT<char> > > &>} if this was a non-unicode build, but don't worry about that, I specified the other for clarity as to what I wanted).

    It is the Type column in the Watch window that I'd like to be output to the Output window.  How would I do this?  Is it possible?


    I don't mind someone marking a post as "Proposed as answer", but DO NOT mark it as "Answered". If I am the OP, I will decide if a post actually answers my post or not. Thank you.

    Monday, July 11, 2016 10:37 PM

All replies

  • Hi A D R I A N,

    Glad to see you:)

    Just to make this issue clearly, do you mean that want to output the really "type Name" to the output window?

    If so, my understanding is that we have to know how the type name attribute show the value in the Watch window firstly.

    I got some information about the type element, based on your description, this issue would be related to the Templated classes.

    I just got the information how the Templated classes were used, but how to read it and output the name to the output window, it would be a real issue, do you want to read the tag in the xml file and custom the output window like this sample?

    https://social.msdn.microsoft.com/Forums/vstudio/en-US/aa7ae984-5c0b-4f2b-a5f0-1ab349490030/is-there-a-way-to-send-debugtrace-messages-to-panes-other-than-the-debug-pane-in-visual-studios?forum=vsdebug#af6bbbe9-eb81-4203-8452-44b9bba84dcc

    If I have misunderstood this issue, please feel free to let me know.

    Best Regards,

    Jack


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.


    Wednesday, July 13, 2016 11:47 AM
    Moderator
  • So, say I had something like the following Item definition:

    <Type Name="CArray&lt;*,*&gt;">
      <DisplayString>{{ size={m_nSize} type={typeid(*this).name()} }}</DisplayString>
    </Type>
    This would output the actual type of the CArray object after the size.


    I don't mind someone marking a post as "Proposed as answer", but DO NOT mark it as "Answered". If I am the OP, I will decide if a post actually answers my post or not. Thank you.

    Wednesday, July 13, 2016 7:34 PM
  • Hi A D R I A N,

    If we want to output messages to the output windows, I know that we could use the Debug.WriteLine() method like this thread here, so maybe I misunderstood this issue before: If we could read the value of the type name, and then output it using the above method would be the workaround for this issue.

    But actually you mean that you want to write the natvis Extension to output the type messages of the watch window to the output window during debug your app automatically, am I right? If so, sorry for that I didn't find a workaround for this issue, but I am trying to involve someone familiar with this topic to further look at this issue. There might be some time delay. Appreciate your patience.

    Sincerely,

    Jack


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Thursday, July 14, 2016 11:57 AM
    Moderator
  • Thanks Jack,

    Yes, I would like it so that natvis will output the type name.  I don't want to involve the rebuilding of the binary.

    I look forward to seeing the results of your search.

    A

    P.S. BTW, your survey link still doesn't work.  This is what I get when I click on that link:

    Survey link result


    I don't mind someone marking a post as "Proposed as answer", but DO NOT mark it as "Answered". If I am the OP, I will decide if a post actually answers my post or not. Thank you.


    Monday, July 18, 2016 6:14 PM