如何在CPP中获得当前版本的Visual Studio进行扩展项目
How do I get the current version of Visual studio in cpp for an extension project?
我当前正在从事Visual Studio扩展项目,我需要在C 代码中读取 CurrentTheme 注册表值。为此,我写了以下代码
CRegKey RegKey;
LPCTSTR keyName; // SoftwareMicrosoftVisualStudio{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
似乎在编译时产生值。我需要动态创建SoftwareMicrosoftVisualStudio{0}General
值,以便我知道在哪个版本的Addin Project正在运行的VisualStudio中。有人可以帮我吗?
我为此找到了解决方法。我使用了当前运行的devenv.exe
的处理程序,并导航到其包装定义文件devenv.pkgdef
并读取该文件中写入的RegistryRoot
值。这给出了我要搜索的SoftwareMicrosoftVisualStudioxx.0
值。
相关文章:
- Visual Studio 2015:Extern "C" 和 "export" 关键字
- 为cl.exe(Visual Studio代码)指定命令行C++版本
- 试图在visual studio上用C++创建一个桌面应用程序
- 如何在MS Visual Studio 2019中运行QT UI
- 如何使用Visual Studio 2017在C++中为参数化对象数组使用唯一指针
- Visual Studio Code - C++ Debugger 無法啟動
- Visual Studio 2019:插入多个C++风格的单行注释
- Visual Studio Code "undefined reference to `WinMain@16'"
- Visual studio代码重构似乎不起作用(例如,重命名符号-f2)
- Visual Studio中的函数声明和函数定义问题
- 如何指定我希望我的LIB链接到的DLL文件?-Visual Studio 2019
- Visual Studio mkl_link_tool.exe链接错误
- Visual Studio(或任何其他工具)能否将地址解释为调用堆栈(boost上下文)的开头
- 不同的Visual Studio版本中缺少.dll
- 用Visual Studio在C++中嵌入Julia
- Visual Studio 2017循环自动向量化问题
- 有没有办法在远程设备上打开和编辑visual Studio 2017解决方案
- 尝试使用继承和模板实现CRTP.Visual Studio正在生成编译器错误
- Visual Studio在尝试读取resource.txt文件时崩溃
- Visual Studio 2017 不允许我创建 C++ 专用模板