How to write a custom native Visual Studio visualizer DLL for a class in another DLL












0















I looked at this great answer.



However as soon as I change the setup as following:




  • create a DLL with a class called JulianDate

  • put the visualiser inside its own project

  • create a separate solution instantiating the class JulianDate


This does not seem to work anymore. As soon as I add the visualiser formatter for the class JulianDate, the visualiser stops working altogether for all classes. I tried copying all the DLL files in this folder but to no avail:




  • C:Users\DocumentsVisual Studio 2013Visualizers


Here is the code sample for JulianDate.h which I put in its own dll.



#if defined(DATELIB_EXPORTS) // inside DLL
# define DATELIB_API __declspec(dllexport)
#else // outside DLL
# define DATELIB_API __declspec(dllimport)
#endif // XYZLIBRARY_EXPORT


class DATELIB_API JulianDate {
public:
JulianDate() : m_date(0) {}
JulianDate(unsigned long dt) : m_date(dt) {}
unsigned long get_date() { return m_date; }
private:
unsigned long m_date;
};


Here is the updated code for the visualiser/formatter, just adding JulianDateFormatter seems to cause some issues in the visualiser:



#include "stdafx.h"
#include "JulianDate.h"

#include <iostream>
#include <windows.h>

#define ADDIN_API __declspec(dllexport)

typedef struct tagDEBUGHELPER
{
DWORD dwVersion;
HRESULT(WINAPI *ReadDebuggeeMemory)(struct tagDEBUGHELPER *pThis, DWORD dwAddr, DWORD nWant, VOID* pWhere, DWORD *nGot);
// from here only when dwVersion >= 0x20000
DWORDLONG(WINAPI *GetRealAddress)(struct tagDEBUGHELPER *pThis);
HRESULT(WINAPI *ReadDebuggeeMemoryEx)(struct tagDEBUGHELPER *pThis, DWORDLONG qwAddr, DWORD nWant, VOID* pWhere, DWORD *nGot);
int (WINAPI *GetProcessorType)(struct tagDEBUGHELPER *pThis);
} DEBUGHELPER;

typedef HRESULT(WINAPI *CUSTOMVIEWER)(DWORD dwAddress, DEBUGHELPER *pHelper, int nBase, BOOL bUniStrings, char *pResult, size_t max, DWORD reserved);

extern "C" ADDIN_API HRESULT MyClassFormatter(DWORD dwAddress, DEBUGHELPER *pHelper, int nBase, BOOL bUniStrings, char *pResult, size_t max, DWORD reserved);
extern "C" ADDIN_API HRESULT MyStructFormatter(DWORD dwAddress, DEBUGHELPER *pHelper, int nBase, BOOL bUniStrings, char *pResult, size_t max, DWORD reserved);
extern "C" ADDIN_API HRESULT JulianDateFormatter(DWORD dwAddress, DEBUGHELPER *pHelper, int nBase, BOOL bUniStrings, char *pResult, size_t max, DWORD reserved);

class MyClass
{
public:
int publicInt;
};

struct MyStruct { int i; };

ADDIN_API HRESULT MyClassFormatter(DWORD dwAddress, DEBUGHELPER *pHelper, int nBase, BOOL bUniStrings, char *pResult, size_t max, DWORD reserved)
{
MyClass c;
DWORD nGot;
pHelper->ReadDebuggeeMemory(pHelper, dwAddress, sizeof(MyClass), &c, &nGot);
sprintf_s(pResult, max, "Dll MyClass: max=%d nGot=%d MyClass=%x publicInt=%d", max, nGot, dwAddress, c.publicInt);
return S_OK;
}

ADDIN_API HRESULT MyStructFormatter(DWORD dwAddress, DEBUGHELPER *pHelper, int nBase, BOOL bUniStrings, char *pResult, size_t max, DWORD reserved)
{
MyStruct s;
DWORD nGot;
pHelper->ReadDebuggeeMemory(pHelper, dwAddress, sizeof(MyStruct), &s, &nGot);
sprintf_s(pResult, max, "Dll MyStruct: max=%d nGot=%d MyStruct=%x i=%d", max, nGot, dwAddress, s.i);
return S_OK;
}

ADDIN_API HRESULT JulianDateFormatter(DWORD dwAddress, DEBUGHELPER *pHelper, int nBase, BOOL bUniStrings, char *pResult, size_t max, DWORD reserved)
{
JulianDate s;
DWORD nGot;
pHelper->ReadDebuggeeMemory(pHelper, dwAddress, sizeof(JulianDate), &s, &nGot);
sprintf_s(pResult, max, "Dll JulianDate: max=%d nGot=%d MyStruct=%x i=%d", max, nGot, dwAddress, s.get_date());
return S_OK;
}


Here is the main I used to debug the visualiser:



#include "stdafx.h"

#include <iostream>
#include "JulianDate.h"

class MyClass
{
public:
int publicInt;
};

struct MyStruct { int i; };

int _tmain(int argc, _TCHAR* argv)
{
struct MyStruct s = { 1234 };
std::cout << s.i << std::endl;
MyClass *c = new MyClass;
c->publicInt = 1234;
std::cout << c->publicInt << std::endl;

JulianDate d(20);

return 0;
}


How can I figure what's going on ?










share|improve this question



























    0















    I looked at this great answer.



    However as soon as I change the setup as following:




    • create a DLL with a class called JulianDate

    • put the visualiser inside its own project

    • create a separate solution instantiating the class JulianDate


    This does not seem to work anymore. As soon as I add the visualiser formatter for the class JulianDate, the visualiser stops working altogether for all classes. I tried copying all the DLL files in this folder but to no avail:




    • C:Users\DocumentsVisual Studio 2013Visualizers


    Here is the code sample for JulianDate.h which I put in its own dll.



    #if defined(DATELIB_EXPORTS) // inside DLL
    # define DATELIB_API __declspec(dllexport)
    #else // outside DLL
    # define DATELIB_API __declspec(dllimport)
    #endif // XYZLIBRARY_EXPORT


    class DATELIB_API JulianDate {
    public:
    JulianDate() : m_date(0) {}
    JulianDate(unsigned long dt) : m_date(dt) {}
    unsigned long get_date() { return m_date; }
    private:
    unsigned long m_date;
    };


    Here is the updated code for the visualiser/formatter, just adding JulianDateFormatter seems to cause some issues in the visualiser:



    #include "stdafx.h"
    #include "JulianDate.h"

    #include <iostream>
    #include <windows.h>

    #define ADDIN_API __declspec(dllexport)

    typedef struct tagDEBUGHELPER
    {
    DWORD dwVersion;
    HRESULT(WINAPI *ReadDebuggeeMemory)(struct tagDEBUGHELPER *pThis, DWORD dwAddr, DWORD nWant, VOID* pWhere, DWORD *nGot);
    // from here only when dwVersion >= 0x20000
    DWORDLONG(WINAPI *GetRealAddress)(struct tagDEBUGHELPER *pThis);
    HRESULT(WINAPI *ReadDebuggeeMemoryEx)(struct tagDEBUGHELPER *pThis, DWORDLONG qwAddr, DWORD nWant, VOID* pWhere, DWORD *nGot);
    int (WINAPI *GetProcessorType)(struct tagDEBUGHELPER *pThis);
    } DEBUGHELPER;

    typedef HRESULT(WINAPI *CUSTOMVIEWER)(DWORD dwAddress, DEBUGHELPER *pHelper, int nBase, BOOL bUniStrings, char *pResult, size_t max, DWORD reserved);

    extern "C" ADDIN_API HRESULT MyClassFormatter(DWORD dwAddress, DEBUGHELPER *pHelper, int nBase, BOOL bUniStrings, char *pResult, size_t max, DWORD reserved);
    extern "C" ADDIN_API HRESULT MyStructFormatter(DWORD dwAddress, DEBUGHELPER *pHelper, int nBase, BOOL bUniStrings, char *pResult, size_t max, DWORD reserved);
    extern "C" ADDIN_API HRESULT JulianDateFormatter(DWORD dwAddress, DEBUGHELPER *pHelper, int nBase, BOOL bUniStrings, char *pResult, size_t max, DWORD reserved);

    class MyClass
    {
    public:
    int publicInt;
    };

    struct MyStruct { int i; };

    ADDIN_API HRESULT MyClassFormatter(DWORD dwAddress, DEBUGHELPER *pHelper, int nBase, BOOL bUniStrings, char *pResult, size_t max, DWORD reserved)
    {
    MyClass c;
    DWORD nGot;
    pHelper->ReadDebuggeeMemory(pHelper, dwAddress, sizeof(MyClass), &c, &nGot);
    sprintf_s(pResult, max, "Dll MyClass: max=%d nGot=%d MyClass=%x publicInt=%d", max, nGot, dwAddress, c.publicInt);
    return S_OK;
    }

    ADDIN_API HRESULT MyStructFormatter(DWORD dwAddress, DEBUGHELPER *pHelper, int nBase, BOOL bUniStrings, char *pResult, size_t max, DWORD reserved)
    {
    MyStruct s;
    DWORD nGot;
    pHelper->ReadDebuggeeMemory(pHelper, dwAddress, sizeof(MyStruct), &s, &nGot);
    sprintf_s(pResult, max, "Dll MyStruct: max=%d nGot=%d MyStruct=%x i=%d", max, nGot, dwAddress, s.i);
    return S_OK;
    }

    ADDIN_API HRESULT JulianDateFormatter(DWORD dwAddress, DEBUGHELPER *pHelper, int nBase, BOOL bUniStrings, char *pResult, size_t max, DWORD reserved)
    {
    JulianDate s;
    DWORD nGot;
    pHelper->ReadDebuggeeMemory(pHelper, dwAddress, sizeof(JulianDate), &s, &nGot);
    sprintf_s(pResult, max, "Dll JulianDate: max=%d nGot=%d MyStruct=%x i=%d", max, nGot, dwAddress, s.get_date());
    return S_OK;
    }


    Here is the main I used to debug the visualiser:



    #include "stdafx.h"

    #include <iostream>
    #include "JulianDate.h"

    class MyClass
    {
    public:
    int publicInt;
    };

    struct MyStruct { int i; };

    int _tmain(int argc, _TCHAR* argv)
    {
    struct MyStruct s = { 1234 };
    std::cout << s.i << std::endl;
    MyClass *c = new MyClass;
    c->publicInt = 1234;
    std::cout << c->publicInt << std::endl;

    JulianDate d(20);

    return 0;
    }


    How can I figure what's going on ?










    share|improve this question

























      0












      0








      0








      I looked at this great answer.



      However as soon as I change the setup as following:




      • create a DLL with a class called JulianDate

      • put the visualiser inside its own project

      • create a separate solution instantiating the class JulianDate


      This does not seem to work anymore. As soon as I add the visualiser formatter for the class JulianDate, the visualiser stops working altogether for all classes. I tried copying all the DLL files in this folder but to no avail:




      • C:Users\DocumentsVisual Studio 2013Visualizers


      Here is the code sample for JulianDate.h which I put in its own dll.



      #if defined(DATELIB_EXPORTS) // inside DLL
      # define DATELIB_API __declspec(dllexport)
      #else // outside DLL
      # define DATELIB_API __declspec(dllimport)
      #endif // XYZLIBRARY_EXPORT


      class DATELIB_API JulianDate {
      public:
      JulianDate() : m_date(0) {}
      JulianDate(unsigned long dt) : m_date(dt) {}
      unsigned long get_date() { return m_date; }
      private:
      unsigned long m_date;
      };


      Here is the updated code for the visualiser/formatter, just adding JulianDateFormatter seems to cause some issues in the visualiser:



      #include "stdafx.h"
      #include "JulianDate.h"

      #include <iostream>
      #include <windows.h>

      #define ADDIN_API __declspec(dllexport)

      typedef struct tagDEBUGHELPER
      {
      DWORD dwVersion;
      HRESULT(WINAPI *ReadDebuggeeMemory)(struct tagDEBUGHELPER *pThis, DWORD dwAddr, DWORD nWant, VOID* pWhere, DWORD *nGot);
      // from here only when dwVersion >= 0x20000
      DWORDLONG(WINAPI *GetRealAddress)(struct tagDEBUGHELPER *pThis);
      HRESULT(WINAPI *ReadDebuggeeMemoryEx)(struct tagDEBUGHELPER *pThis, DWORDLONG qwAddr, DWORD nWant, VOID* pWhere, DWORD *nGot);
      int (WINAPI *GetProcessorType)(struct tagDEBUGHELPER *pThis);
      } DEBUGHELPER;

      typedef HRESULT(WINAPI *CUSTOMVIEWER)(DWORD dwAddress, DEBUGHELPER *pHelper, int nBase, BOOL bUniStrings, char *pResult, size_t max, DWORD reserved);

      extern "C" ADDIN_API HRESULT MyClassFormatter(DWORD dwAddress, DEBUGHELPER *pHelper, int nBase, BOOL bUniStrings, char *pResult, size_t max, DWORD reserved);
      extern "C" ADDIN_API HRESULT MyStructFormatter(DWORD dwAddress, DEBUGHELPER *pHelper, int nBase, BOOL bUniStrings, char *pResult, size_t max, DWORD reserved);
      extern "C" ADDIN_API HRESULT JulianDateFormatter(DWORD dwAddress, DEBUGHELPER *pHelper, int nBase, BOOL bUniStrings, char *pResult, size_t max, DWORD reserved);

      class MyClass
      {
      public:
      int publicInt;
      };

      struct MyStruct { int i; };

      ADDIN_API HRESULT MyClassFormatter(DWORD dwAddress, DEBUGHELPER *pHelper, int nBase, BOOL bUniStrings, char *pResult, size_t max, DWORD reserved)
      {
      MyClass c;
      DWORD nGot;
      pHelper->ReadDebuggeeMemory(pHelper, dwAddress, sizeof(MyClass), &c, &nGot);
      sprintf_s(pResult, max, "Dll MyClass: max=%d nGot=%d MyClass=%x publicInt=%d", max, nGot, dwAddress, c.publicInt);
      return S_OK;
      }

      ADDIN_API HRESULT MyStructFormatter(DWORD dwAddress, DEBUGHELPER *pHelper, int nBase, BOOL bUniStrings, char *pResult, size_t max, DWORD reserved)
      {
      MyStruct s;
      DWORD nGot;
      pHelper->ReadDebuggeeMemory(pHelper, dwAddress, sizeof(MyStruct), &s, &nGot);
      sprintf_s(pResult, max, "Dll MyStruct: max=%d nGot=%d MyStruct=%x i=%d", max, nGot, dwAddress, s.i);
      return S_OK;
      }

      ADDIN_API HRESULT JulianDateFormatter(DWORD dwAddress, DEBUGHELPER *pHelper, int nBase, BOOL bUniStrings, char *pResult, size_t max, DWORD reserved)
      {
      JulianDate s;
      DWORD nGot;
      pHelper->ReadDebuggeeMemory(pHelper, dwAddress, sizeof(JulianDate), &s, &nGot);
      sprintf_s(pResult, max, "Dll JulianDate: max=%d nGot=%d MyStruct=%x i=%d", max, nGot, dwAddress, s.get_date());
      return S_OK;
      }


      Here is the main I used to debug the visualiser:



      #include "stdafx.h"

      #include <iostream>
      #include "JulianDate.h"

      class MyClass
      {
      public:
      int publicInt;
      };

      struct MyStruct { int i; };

      int _tmain(int argc, _TCHAR* argv)
      {
      struct MyStruct s = { 1234 };
      std::cout << s.i << std::endl;
      MyClass *c = new MyClass;
      c->publicInt = 1234;
      std::cout << c->publicInt << std::endl;

      JulianDate d(20);

      return 0;
      }


      How can I figure what's going on ?










      share|improve this question














      I looked at this great answer.



      However as soon as I change the setup as following:




      • create a DLL with a class called JulianDate

      • put the visualiser inside its own project

      • create a separate solution instantiating the class JulianDate


      This does not seem to work anymore. As soon as I add the visualiser formatter for the class JulianDate, the visualiser stops working altogether for all classes. I tried copying all the DLL files in this folder but to no avail:




      • C:Users\DocumentsVisual Studio 2013Visualizers


      Here is the code sample for JulianDate.h which I put in its own dll.



      #if defined(DATELIB_EXPORTS) // inside DLL
      # define DATELIB_API __declspec(dllexport)
      #else // outside DLL
      # define DATELIB_API __declspec(dllimport)
      #endif // XYZLIBRARY_EXPORT


      class DATELIB_API JulianDate {
      public:
      JulianDate() : m_date(0) {}
      JulianDate(unsigned long dt) : m_date(dt) {}
      unsigned long get_date() { return m_date; }
      private:
      unsigned long m_date;
      };


      Here is the updated code for the visualiser/formatter, just adding JulianDateFormatter seems to cause some issues in the visualiser:



      #include "stdafx.h"
      #include "JulianDate.h"

      #include <iostream>
      #include <windows.h>

      #define ADDIN_API __declspec(dllexport)

      typedef struct tagDEBUGHELPER
      {
      DWORD dwVersion;
      HRESULT(WINAPI *ReadDebuggeeMemory)(struct tagDEBUGHELPER *pThis, DWORD dwAddr, DWORD nWant, VOID* pWhere, DWORD *nGot);
      // from here only when dwVersion >= 0x20000
      DWORDLONG(WINAPI *GetRealAddress)(struct tagDEBUGHELPER *pThis);
      HRESULT(WINAPI *ReadDebuggeeMemoryEx)(struct tagDEBUGHELPER *pThis, DWORDLONG qwAddr, DWORD nWant, VOID* pWhere, DWORD *nGot);
      int (WINAPI *GetProcessorType)(struct tagDEBUGHELPER *pThis);
      } DEBUGHELPER;

      typedef HRESULT(WINAPI *CUSTOMVIEWER)(DWORD dwAddress, DEBUGHELPER *pHelper, int nBase, BOOL bUniStrings, char *pResult, size_t max, DWORD reserved);

      extern "C" ADDIN_API HRESULT MyClassFormatter(DWORD dwAddress, DEBUGHELPER *pHelper, int nBase, BOOL bUniStrings, char *pResult, size_t max, DWORD reserved);
      extern "C" ADDIN_API HRESULT MyStructFormatter(DWORD dwAddress, DEBUGHELPER *pHelper, int nBase, BOOL bUniStrings, char *pResult, size_t max, DWORD reserved);
      extern "C" ADDIN_API HRESULT JulianDateFormatter(DWORD dwAddress, DEBUGHELPER *pHelper, int nBase, BOOL bUniStrings, char *pResult, size_t max, DWORD reserved);

      class MyClass
      {
      public:
      int publicInt;
      };

      struct MyStruct { int i; };

      ADDIN_API HRESULT MyClassFormatter(DWORD dwAddress, DEBUGHELPER *pHelper, int nBase, BOOL bUniStrings, char *pResult, size_t max, DWORD reserved)
      {
      MyClass c;
      DWORD nGot;
      pHelper->ReadDebuggeeMemory(pHelper, dwAddress, sizeof(MyClass), &c, &nGot);
      sprintf_s(pResult, max, "Dll MyClass: max=%d nGot=%d MyClass=%x publicInt=%d", max, nGot, dwAddress, c.publicInt);
      return S_OK;
      }

      ADDIN_API HRESULT MyStructFormatter(DWORD dwAddress, DEBUGHELPER *pHelper, int nBase, BOOL bUniStrings, char *pResult, size_t max, DWORD reserved)
      {
      MyStruct s;
      DWORD nGot;
      pHelper->ReadDebuggeeMemory(pHelper, dwAddress, sizeof(MyStruct), &s, &nGot);
      sprintf_s(pResult, max, "Dll MyStruct: max=%d nGot=%d MyStruct=%x i=%d", max, nGot, dwAddress, s.i);
      return S_OK;
      }

      ADDIN_API HRESULT JulianDateFormatter(DWORD dwAddress, DEBUGHELPER *pHelper, int nBase, BOOL bUniStrings, char *pResult, size_t max, DWORD reserved)
      {
      JulianDate s;
      DWORD nGot;
      pHelper->ReadDebuggeeMemory(pHelper, dwAddress, sizeof(JulianDate), &s, &nGot);
      sprintf_s(pResult, max, "Dll JulianDate: max=%d nGot=%d MyStruct=%x i=%d", max, nGot, dwAddress, s.get_date());
      return S_OK;
      }


      Here is the main I used to debug the visualiser:



      #include "stdafx.h"

      #include <iostream>
      #include "JulianDate.h"

      class MyClass
      {
      public:
      int publicInt;
      };

      struct MyStruct { int i; };

      int _tmain(int argc, _TCHAR* argv)
      {
      struct MyStruct s = { 1234 };
      std::cout << s.i << std::endl;
      MyClass *c = new MyClass;
      c->publicInt = 1234;
      std::cout << c->publicInt << std::endl;

      JulianDate d(20);

      return 0;
      }


      How can I figure what's going on ?







      c++ visual-studio






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 21 '18 at 21:00









      BlueTrinBlueTrin

      5,01853764




      5,01853764
























          0






          active

          oldest

          votes











          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53420410%2fhow-to-write-a-custom-native-visual-studio-visualizer-dll-for-a-class-in-another%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          0






          active

          oldest

          votes








          0






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes
















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53420410%2fhow-to-write-a-custom-native-visual-studio-visualizer-dll-for-a-class-in-another%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          How to change which sound is reproduced for terminal bell?

          Can I use Tabulator js library in my java Spring + Thymeleaf project?

          Title Spacing in Bjornstrup Chapter, Removing Chapter Number From Contents