0

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?

viki
  • 1,178
  • 1
  • 17
  • 22
  • Use dte.Version and see http://stackoverflow.com/questions/15920572/how-to-get-current-used-color-theme-of-visual-studio2012 – Sergey Vlasov Mar 03 '17 at 09:25

1 Answers1

0

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. This gives the Software\Microsoft\VisualStudio\xx.0 value which I was searching for.

viki
  • 1,178
  • 1
  • 17
  • 22