I am currently working on Visual studio extension project where I need to read the CurrentTheme registry value in c++ code. 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. 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. Could anyone please help me in this?