Support
Joined: 18 Jul 2005 Posts: 731
|
Posted: Sat Aug 23, 2008 8:47 am Post subject: HOWTO: Register a namespace extension under multiple locations |
|
|
It may be sometimes desirable to show the same namespace extension under multiple locations such as the Desktop, My Computer, a file system folder. In this case, override the GetExtensionTargetInfo method of the CNSEFolder-derived class representing the root folder of the namespace extension and add registration targets. The following code (taken from RegistryBrowser sample) demonstrates this :
void CRegBrowserRoot::GetExtensionTargetInfo(CExtensionTargetInfo& info)
{
// IMPORTANT : Allocate with 'new'
CNSETargetInfo* nti1 = new CNSETargetInfo();
// Register as a protocol
nti1->nseTarget= NSET_ProtocolHandler;
nti1->name = _T("RegistryBrowser");
nti1->attributes = (NSEItemAttributes)(NSEIA_Folder | NSEIA_HasSubFolder | NSEIA_Browsable);
//Our namespace extension can be accessed through strings such as reg://HKEY_CURRENT_USER
nti1->protocol = protocol;
nti1->iconFile = _T("c:\\windows\\regedit.exe");
nti1->iconIndex = 0;
nti1->infoTip = _T("Browse the Registry");
// Add the target location to the list
info.AddTarget(nti1);
CNSETargetInfo* nti2 = new CNSETargetInfo();
// Register under 'My Computer'
nti2->nseTarget=NSET_MyComputer;
nti2->name = _T("RegistryBrowser");
nti2->attributes = (NSEItemAttributes)(NSEIA_Folder | NSEIA_HasSubFolder | NSEIA_Browsable);
nti2->iconFile = _T("c:\\windows\\regedit.exe");
nti2->iconIndex = 0;
nti2->infoTip = _T("Browse the Registry");
// Add the target location to the list
info.AddTarget(nti2);
}
Notes:
1. When the same namespace extension is registered under multiple file system folders (NSETarget.FileSystemFolder), the 'context' can be determined using the GetTargetFileOrFolder method of CNSEFolder.
2. If you need to determine the 'context' in other cases (such as differentiating whether the namespace extension is under the 'Desktop' or 'My Computer'), the following must be done:
Additional classes must be derived from the class representing the root folder of the namespace extension. The
GetExtensionTargetInfo method must be overridden in each class to target the respective location. A common variable can be initialized in the constructor of each derived class so that the 'context' is known. The following pseudo-code demonstrates this :
// CBaseWithAllFunctionality .h file:
class CBaseWithAllFunctionality : public CNSEFolder
{
public:
DECLARE_DYNCREATE(CBaseWithAllFunctionality)
DECLARE_OLECREATE_EX(CBaseWithAllFunctionality )
NSETarget target;// this will be initialized in derived classes
CBaseWithAllFunctionality ();
...
...
}
/////////////////////////////////////////////////////////////////////////////////////////
// CBaseWithAllFunctionality .cpp file:
IMPLEMENT_DYNCREATE(CBaseWithAllFunctionality , CNSEFolder)
// The GUID of the class representing the root folder is used as the GUID for the namespace extension
//This GUID should be unique
// {xxxxxxx-xxxx-xxx-.........}
IMPLEMENT_OLECREATE_EX(CBaseWithAllFunctionality , "MyEZNamespaceExtensions.BaseClass",
0x.......,0x....,0x....,0x..,0x..,0x..,0x..,0x..,0x..,0x..,0x.. )
void CBaseWithAllFunctionality ::GetCLSID(LPCLSID pCLSID)
{
*pCLSID = guid;
}
...
...
/////////////////////////////////////////////////////////////////////////////////////////
//Derived CNSEUnderMyComputer .h file
class CNSEUnderMyComputer : public CBaseWithAllFunctionality
{
public:
DECLARE_DYNCREATE(CNSEUnderMyComputer)
DECLARE_OLECREATE_EX(CNSEUnderMyComputer)
CNSEUnderMyComputer(void);
virtual void GetCLSID(LPCLSID pCLSID);
virtual void GetExtensionTargetInfo(CExtensionTargetInfo& info);
...
...
};
/////////////////////////////////////////////////////////////////////////////////////////
//Derived CNSEUnderMyComputer .cpp file
CNSEUnderMyComputer ::CNSEUnderMyComputer ()
{
// Store target for each in parent class
target= NSET_MyComputer;
}
IMPLEMENT_DYNCREATE(CNSEUnderMyComputer , CBaseWithAllFunctionality )
// The GUID of the class representing the root folder is used as the GUID for the namespace extension
//This GUID should be unique
// {xxxxxxx-xxxx-xxx-.........}
IMPLEMENT_OLECREATE_EX(CNSEUnderMyComputer , "MyEZNamespaceExtensions.UnderMyComputer",
0x.......,0x....,0x....,0x..,0x..,0x..,0x..,0x..,0x..,0x..,0x.. )
// This function is called when you register the namespace extension dll file
// using the regsvr32.exe or similar utility
//The classfactory is nested in your class and has a name formed
//by concatenating the class name with "Factory".
BOOL CNSEUnderMyComputer ::CNSEUnderMyComputerFactory::UpdateRegistry(BOOL bRegister)
{
if (bRegister)
{
BOOL ret = AfxOleRegisterServerClass(m_clsid, m_lpszProgID,
m_lpszProgID, m_lpszProgID, OAT_DISPATCH_OBJECT);
// Register the namespace extension
CNSEFolder::RegisterExtension(RUNTIME_CLASS(CNSEUnderMyComputer));
return ret;
}
else
{
// Unregister the namespace extension
CNSEFolder::UnregisterExtension(RUNTIME_CLASS(CNSEUnderMyComputer));
return AfxOleUnregisterClass(m_clsid, m_lpszProgID);
}
}
void CNSEUnderMyComputer ::GetCLSID(LPCLSID pCLSID)
{
*pCLSID = guid;
}
void CNSEUnderMyComputer ::GetExtensionTargetInfo(CExtensionTargetInfo& info)
{
// IMPORTANT : Allocate with 'new'
CNSETargetInfo* nti = new CNSETargetInfo();
// Located under 'My Computer'
nti->nseTarget=NSET_MyComputer;
nti->name = _T("EZNamespaceExtensions");
nti->attributes = (NSEItemAttributes)(NSEIA_Folder | NSEIA_HasSubFolder | NSEIA_Browsable);
TCHAR buf[MAX_PATH];
GetWindowsDirectory( buf, MAX_PATH );
TCHAR path[MAX_PATH];
PathCombine(path,buf,_T("regedit.exe"));
nti->iconFile = path;
nti->iconIndex = 0;
nti->infoTip = _T("EZNamespaceExtensions");
// Add the target location to the list
info.AddTarget(nti);
}
...
...
/////////////////////////////////////////////////////////////////////////////////////////
//Derived CNSEUnderDesktop .h file
class CNSEUnderDesktop : public CBaseWithAllFunctionality
{
public:
DECLARE_DYNCREATE(CNSEUnderDesktop)
DECLARE_OLECREATE_EX(CNSEUnderDesktop)
CNSEUnderDesktop(void);
virtual void GetCLSID(LPCLSID pCLSID);
virtual void GetExtensionTargetInfo(CExtensionTargetInfo& info);
...
...
};
/////////////////////////////////////////////////////////////////////////////////////////
//Derived CNSEUnderDesktop .cpp file
CNSEUnderDesktop ::CNSEUnderDesktop ()
{
// Store target for each in parent class
target= NSET_Desktop;
}
IMPLEMENT_DYNCREATE(CNSEUnderDesktop , CBaseWithAllFunctionality )
// The GUID of the class representing the root folder is used as the GUID for the namespace extension
//This GUID should be unique
// {xxxxxxx-xxxx-xxx-.........}
IMPLEMENT_OLECREATE_EX(CNSEUnderDesktop , "MyEZNamespaceExtensions.UnderDesktop",
0x.......,0x....,0x....,0x..,0x..,0x..,0x..,0x..,0x..,0x..,0x.. )
// This function is called when you register the namespace extension dll file
// using the regsvr32.exe or similar utility
//The classfactory is nested in your class and has a name formed
//by concatenating the class name with "Factory".
BOOL CNSEUnderDesktop ::CNSEUnderDesktopFactory::UpdateRegistry(BOOL bRegister)
{
if (bRegister)
{
BOOL ret = AfxOleRegisterServerClass(m_clsid, m_lpszProgID,
m_lpszProgID, m_lpszProgID, OAT_DISPATCH_OBJECT);
// Register the namespace extension
CNSEFolder::RegisterExtension(RUNTIME_CLASS(CNSEUnderDesktop));
return ret;
}
else
{
// Unregister the namespace extension
CNSEFolder::UnregisterExtension(RUNTIME_CLASS(CNSEUnderDesktop));
return AfxOleUnregisterClass(m_clsid, m_lpszProgID);
}
}
void CNSEUnderDesktop::GetCLSID(LPCLSID pCLSID)
{
*pCLSID = guid;
}
void CNSEUnderDesktop::GetExtensionTargetInfo(CExtensionTargetInfo& info)
{
// IMPORTANT : Allocate with 'new'
CNSETargetInfo* nti = new CNSETargetInfo();
nti->nseTarget=NSET_Desktop;
nti->name = _T("EZNamespaceExtensions");
nti->attributes = (NSEItemAttributes)(NSEIA_Folder | NSEIA_HasSubFolder | NSEIA_Browsable);
TCHAR buf[MAX_PATH];
GetWindowsDirectory( buf, MAX_PATH );
TCHAR path[MAX_PATH];
PathCombine(path,buf,_T("regedit.exe"));
nti->iconFile = path;
nti->iconIndex = 0;
nti->infoTip = _T("EZNamespaceExtensions");
// Add the target location to the list
info.AddTarget(nti);
}
...
... |
|