[英]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.