如何为另一个DLL中的类编写自定义本机Visual Studio可视化程序DLL

时间:2018-11-21 21:00:30

标签: c++ visual-studio

我看着这个很棒的answer

但是,一旦我按如下所示更改设置:

  • 使用名为JulianDate的类创建DLL
  • 将可视化工具放入自己的项目中
  • 创建一个单独的解决方案,实例化类JulianDate

这似乎不再起作用。一旦为类JulianDate添加了可视化工具格式化程序,该可视化工具将针对所有类完全停止工作。我尝试复制此文件夹中的所有DLL文件,但无济于事:

  • C:\ Users \\ Documents \ Visual Studio 2013 \ Visualizers

这是JulianDate.h的代码示例,我将其放在自己的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;
};

以下是可视化工具/格式化程序的更新代码,仅添加JulianDateFormatter似乎会在可视化工具中引起一些问题:

#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;
}

这是我用来调试展示台的主要工具:

#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;
}

我怎么知道发生了什么事?

0 个答案:

没有答案