【问题标题】:How do I get the current version of Visual studio in cpp for an extension project?如何在 cpp 中为扩展项目获取当前版本的 Visual Studio?
【发布时间】:2017-03-01 11:17:10
【问题描述】:

我目前正在开发 Visual Studio 扩展项目,我需要在 C++ 代码中读取 CurrentTheme 注册表值。为此,我编写了以下代码

CRegKey RegKey;
LPCTSTR keyName; // Software\Microsoft\VisualStudio\{0}\General
//LPTSTR keyValue;

#if _MSC_VER >= 1600 && _MSC_VER < 1700 // VS 2010
keyName = _T("Software\\Microsoft\\VisualStudio\\10.0\\General");
#elif _MSC_VER >= 1700 && _MSC_VER < 1800 // VS 2012
keyName = _T("Software\\Microsoft\\VisualStudio\\11.0\\General");
#elif _MSC_VER >= 1800 && _MSC_VER < 1900 // VS 2013
keyName = _T("Software\\Microsoft\\VisualStudio\\12.0\\General");
#elif _MSC_VER >= 1900 && _MSC_VER < 2000 // VS 2015
keyName = _T("Software\\Microsoft\\VisualStudio\\14.0\\General");
#endif

LONG lResult = RegKey.Open( HKEY_CURRENT_USER, keyName, KEY_READ );
MessageBox(NULL, _MSC_VER , _T("Msg"), MB_OK | MB_ICONERROR);
if( ERROR_SUCCESS != lResult )
{
    return false;
}

ULONG chars;
CString keyValue;

if (RegKey.QueryStringValue(L"CurrentTheme", 0, &chars) == ERROR_SUCCESS)
{
    RegKey.QueryStringValue(L"CurrentTheme", keyValue.GetBuffer(chars), &chars);
    keyValue.ReleaseBuffer();
    MessageBox(NULL, keyValue , _T("Msg"), MB_OK | MB_ICONERROR);
}
RegKey.Close();

但是_MSC_VER 似乎在编译时产生了价值。我需要动态创建 Software\Microsoft\VisualStudio\{0}\General 值,以便了解我的插件项目在哪个版本的 VisualStudio 中运行。有人可以帮我吗?

【问题讨论】:

标签: c++ visual-studio visual-studio-addins


【解决方案1】:

我找到了解决方法。我使用当前正在运行的devenv.exe 的处理程序并导航到它的包定义文件devenv.pkgdef 并读取写入该文件中的RegistryRoot 值。这给出了我正在搜索的 Software\Microsoft\VisualStudio\xx.0 值。

【讨论】:

    猜你喜欢
    • 2013-09-30
    • 2022-08-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-08-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多