简体   繁体   English

如何为扩展项目在cpp中获得Visual Studio的当前版本?

[英]How do I get the current version of Visual studio in cpp for an extension project?

I am currently working on Visual studio extension project where I need to read the CurrentTheme registry value in c++ code. 我目前在Visual Studio扩展项目上工作,需要在C ++代码中读取CurrentTheme注册表值。 For that I have written the following code 为此,我编写了以下代码

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();

But _MSC_VER seems to produce value at compile time. 但是_MSC_VER似乎在编译时产生了价值。 I need to create the Software\\Microsoft\\VisualStudio\\{0}\\General value dynamically so that I get to know in which version of VisualStudio my addin project is running. 我需要动态创建Software\\Microsoft\\VisualStudio\\{0}\\General值,以便了解我的外接程序项目在哪个VisualStudio版本中运行。 Could anyone please help me in this? 有人可以帮我吗?

I found a workaround for this. 我找到了解决方法。 I used the current running devenv.exe 's handler and navigated to it's package definition file devenv.pkgdef and read the RegistryRoot value written in that file. 我使用了当前正在运行的devenv.exe的处理程序,并导航到其程序包定义文件devenv.pkgdef并读取了写入该文件的RegistryRoot值。 This gives the Software\\Microsoft\\VisualStudio\\xx.0 value which I was searching for. 这给出了我正在搜索的Software\\Microsoft\\VisualStudio\\xx.0值。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何将 RtMidi.cpp 和 RtMidi.h 文件添加到 Visual Studio 2019 到我的项目中? - How do I add RtMidi.cpp and RtMidi.h files to Visual Studio 2019 to my project? 如何在Visual Studio中调试单个.cpp文件? - How do I debug a single .cpp file in Visual Studio? 如何在 Visual Studio 中运行 .cpp 文件? - How do I run .cpp files in Visual Studio? 如何在Visual Studio 2008中的cpp项目中使用外部cpp项目 - How to use external cpp projects in a cpp project in Visual Studio 2008 如何设置Visual Studio 2010项目以为Slickedit 17构建64位扩展名dll? - How do I set up a Visual Studio 2010 project for building a 64 bit extension dll for Slickedit 17? Visual Studio中的控制台cpp项目 - Console cpp project in Visual Studio 如何#include<torch.extension.h> 在 Visual Studio 的 .cpp 文件中? - how to #include<torch.extension.h> in a .cpp file with Visual Studio? 如何从现有的 visual studio CPP 项目创建 Cmake 文件? - How Can I create a Cmake file from existing visual studio CPP project? 如何修复 Visual Studio 的 qt 扩展? - how do i fix the qt extension for visual studio? 如何告诉Visual Studio包含库的.cpp文件? - How do I tell Visual Studio to include a library's .cpp file?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM