【发布时间】: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 中运行。有人可以帮我吗?
【问题讨论】:
-
使用 dte.Version 看stackoverflow.com/questions/15920572/…
标签: c++ visual-studio visual-studio-addins