/**********************************************************************/ /** Microsoft Windows/NT **/ /** Copyright(c) Microsoft Corporation, 1997 - 1999 **/ /**********************************************************************/ /* dynext.cpp dynamic extension helper FILE HISTORY: */ #include "stdafx.h" #include "Dynext.h" #include "tregkey.h" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif const TCHAR g_szContextMenu[] = TEXT("ContextMenu"); const TCHAR g_szNameSpace[] = TEXT("NameSpace"); const TCHAR g_szPropertySheet[] = TEXT("PropertySheet"); const TCHAR g_szToolbar[] = TEXT("Toolbar"); const TCHAR g_szExtensions[] = TEXT("Extensions"); const TCHAR g_szTask[] = TEXT("Task"); const TCHAR g_szDynamicExtensions[] = TEXT("Dynamic Extensions"); const TCHAR NODE_TYPES_KEY[] = TEXT("Software\\Microsoft\\MMC\\NodeTypes"); const TCHAR SNAPINS_KEY[] = TEXT("Software\\Microsoft\\MMC\\SnapIns"); CDynamicExtensions::CDynamicExtensions() { m_bLoaded = FALSE; } CDynamicExtensions::~CDynamicExtensions() { } HRESULT CDynamicExtensions::SetNode(const GUID * guid) { m_guidNode = *guid; return hrOK; } HRESULT CDynamicExtensions::Reset() { HRESULT hr = hrOK; m_aNameSpace.RemoveAll(); m_aMenu.RemoveAll(); m_aToolbar.RemoveAll(); m_aPropSheet.RemoveAll(); m_aTask.RemoveAll(); m_bLoaded = FALSE; return hr; } HRESULT CDynamicExtensions::Load() { HRESULT hr = hrOK; LONG lRes; CGUIDArray aDynExtensions; Reset(); OLECHAR szGuid[128] = {0}; ::StringFromGUID2(m_guidNode, szGuid, 128); RegKey regkeyNodeTypes; // Change by kmurthy: Instead of default, now open for Read lRes = regkeyNodeTypes.Open(HKEY_LOCAL_MACHINE, NODE_TYPES_KEY, KEY_READ); Assert(lRes == ERROR_SUCCESS); if (lRes != ERROR_SUCCESS) { return HRESULT_FROM_WIN32(lRes); // failed to open } RegKey regkeyNode; // Change by kmurthy: Instead of default, now open for Read lRes = regkeyNode.Open(regkeyNodeTypes, szGuid, KEY_READ); if (lRes != ERROR_SUCCESS) { return HRESULT_FROM_WIN32(lRes); // failed to open } // open the key for dynamic extensions and enumerate RegKey regkeyDynExt; // Change by kmurthy: Instead of default, now open for Read lRes = regkeyDynExt.Open(regkeyNode, g_szDynamicExtensions, KEY_READ); if (lRes != ERROR_SUCCESS) { return HRESULT_FROM_WIN32(lRes); // failed to open } RegKey regkeyExtensions; // Change by kmurthy: Instead of default, now open for Read lRes = regkeyExtensions.Open(regkeyNode, g_szExtensions, KEY_READ); if (lRes != ERROR_SUCCESS) { return HRESULT_FROM_WIN32(lRes); // failed to open } CString strKey; RegValueIterator iterDynExt; iterDynExt.Init(®keyDynExt); while (iterDynExt.Next(&strKey, NULL) == hrOK) { GUID guid; ::CLSIDFromString(((LPTSTR) (LPCTSTR) strKey), &guid); if (!aDynExtensions.IsInList(guid)) aDynExtensions.Add(guid); } // ok, have the list of dynamic extensions, now enumerate the various extension types // namespace extensions RegKey regkeyNSExt; // Change by kmurthy: Instead of default, now open for Read lRes = regkeyNSExt.Open(regkeyExtensions, g_szNameSpace, KEY_READ); if (lRes == ERROR_SUCCESS) { // enumerate the ns dynamic extensions RegValueIterator iterNSExt; iterNSExt.Init(®keyNSExt); while (iterNSExt.Next(&strKey, NULL) == hrOK) { GUID guid; ::CLSIDFromString(((LPTSTR) (LPCTSTR) strKey), &guid); if (aDynExtensions.IsInList(guid)) m_aNameSpace.Add(guid); } } // Menu extensions RegKey regkeyMenuExt; // Change by kmurthy: Instead of default, now open for Read lRes = regkeyMenuExt.Open(regkeyExtensions, g_szContextMenu, KEY_READ); if (lRes == ERROR_SUCCESS) { // enumerate the ns dynamic extensions RegValueIterator iterMenuExt; iterMenuExt.Init(®keyMenuExt); while (iterMenuExt.Next(&strKey, NULL) == hrOK) { GUID guid; ::CLSIDFromString(((LPTSTR) (LPCTSTR) strKey), &guid); if (aDynExtensions.IsInList(guid)) m_aMenu.Add(guid); } } // toolbar extensions RegKey regkeyToolbarExt; // Change by kmurthy: Instead of default, now open for Read lRes = regkeyToolbarExt.Open(regkeyExtensions, g_szToolbar, KEY_READ); if (lRes == ERROR_SUCCESS) { // enumerate the ns dynamic extensions RegValueIterator iterToolbarExt; iterToolbarExt.Init(®keyToolbarExt); while (iterToolbarExt.Next(&strKey, NULL) == hrOK) { GUID guid; ::CLSIDFromString(((LPTSTR) (LPCTSTR) strKey), &guid); if (aDynExtensions.IsInList(guid)) m_aToolbar.Add(guid); } } // PropPage extensions RegKey regkeyPSExt; // Change by kmurthy: Instead of default, now open for Read lRes = regkeyPSExt.Open(regkeyExtensions, g_szPropertySheet, KEY_READ); if (lRes == ERROR_SUCCESS) { // enumerate the ns dynamic extensions RegValueIterator iterPSExt; iterPSExt.Init(®keyPSExt); while (iterPSExt.Next(&strKey, NULL) == hrOK) { GUID guid; ::CLSIDFromString(((LPTSTR) (LPCTSTR) strKey), &guid); if (aDynExtensions.IsInList(guid)) m_aPropSheet.Add(guid); } } // taskpad extensions RegKey regkeyTaskExt; // Change by kmurthy: Instead of default, now open for Read lRes = regkeyTaskExt.Open(regkeyExtensions, g_szTask, KEY_READ); if (lRes == ERROR_SUCCESS) { // enumerate the ns dynamic extensions RegValueIterator iterTaskExt; iterTaskExt.Init(®keyTaskExt); while (iterTaskExt.Next(&strKey, NULL) == hrOK) { GUID guid; ::CLSIDFromString(((LPTSTR) (LPCTSTR) strKey), &guid); if (aDynExtensions.IsInList(guid)) m_aTask.Add(guid); } } m_bLoaded = TRUE; return hr; } HRESULT CDynamicExtensions::GetNamespaceExtensions(CGUIDArray & aGuids) { HRESULT hr = hrOK; aGuids.Copy(m_aNameSpace); return hr; } HRESULT CDynamicExtensions::BuildMMCObjectTypes(HGLOBAL * phGlobal) { HRESULT hr = hrOK; HGLOBAL hGlobal = NULL; SMMCDynamicExtensions * pDynExt = NULL; if (phGlobal) *phGlobal = NULL; COM_PROTECT_TRY { int i; CGUIDArray aOtherDynExt; // build our main list of other extension types // other means everything except namespace for (i = 0; i < m_aMenu.GetSize(); i++) { if (!aOtherDynExt.IsInList(m_aMenu[i])) aOtherDynExt.Add(m_aMenu[i]); } for (i = 0; i < m_aToolbar.GetSize(); i++) { if (!aOtherDynExt.IsInList(m_aToolbar[i])) aOtherDynExt.Add(m_aToolbar[i]); } for (i = 0; i < m_aPropSheet.GetSize(); i++) { if (!aOtherDynExt.IsInList(m_aPropSheet[i])) aOtherDynExt.Add(m_aPropSheet[i]); } for (i = 0; i < m_aTask.GetSize(); i++) { if (!aOtherDynExt.IsInList(m_aTask[i])) aOtherDynExt.Add(m_aTask[i]); } int nCount = (int)aOtherDynExt.GetSize(); hGlobal = (SMMCDynamicExtensions *) ::GlobalAlloc(GMEM_SHARE | GMEM_MOVEABLE, sizeof(SMMCDynamicExtensions) + (nCount * sizeof(GUID))); pDynExt = reinterpret_cast(::GlobalLock(hGlobal)); if (!pDynExt) { hr = E_OUTOFMEMORY; goto Error; } ZeroMemory(pDynExt, sizeof(SMMCDynamicExtensions) + (nCount * sizeof(GUID))); // now build the real struct pDynExt->count = nCount; for (i = 0; i < nCount; i++) { pDynExt->guid[i] = aOtherDynExt[i]; } ::GlobalUnlock(hGlobal); COM_PROTECT_ERROR_LABEL; } COM_PROTECT_CATCH if (SUCCEEDED(hr) && phGlobal) *phGlobal = hGlobal; return hr; }