Click here to Skip to main content
15,881,139 members
Articles / Desktop Programming / ATL

The Mini Shell Extension Framework – Part III

Rate me:
Please Sign up or sign in to vote.
4.96/5 (11 votes)
18 Sep 200516 min read 139.6K   1.4K   46  
Discussion of a small C++ framework to create Windows shell extensions (IShellFolderImpl).
//
// (C) Copyright by Victor Derks <vba64@xs4all.nl>
//
// See README.TXT for the details of the software licence.
//
#pragma once


#include "olestring.h"
#include "strutil.h"


namespace MSF
{

inline HRESULT UpdateRegistryFromResource(UINT nResId, BOOL bRegister, const wchar_t* szDescription, const CLSID& clsid) throw()
{
	COleString olestrCLSID;

	ATLVERIFY(SUCCEEDED(::StringFromCLSID(clsid, olestrCLSID)));

	_ATL_REGMAP_ENTRY regmapEntries[] =
	{
		{L"DESCRIPTION", szDescription},
		{L"CLSID", olestrCLSID},
		{NULL, NULL}
	};

	return ATL::_pAtlModule->UpdateRegistryFromResource(nResId, bRegister, regmapEntries);
}


// Registration function to register the COM object + the root extension.
inline HRESULT UpdateRegistryForRootExt(UINT nResId, BOOL bRegister,
	const wchar_t* szDescription, const CLSID& clsid, const wchar_t* szRootExt) throw()
{
	COleString olestrCLSID;

	ATLVERIFY(SUCCEEDED(StringFromCLSID(clsid, olestrCLSID)));

	_ATL_REGMAP_ENTRY regmapEntries[] =
	{
		{L"DESCRIPTION", szDescription},
		{L"CLSID", olestrCLSID},
		{L"ROOTTYPE", szRootExt},
		{NULL, NULL}
	};

	return ATL::_pAtlModule->UpdateRegistryFromResource(nResId, bRegister, regmapEntries);
}


// Registration function to register the extension based on the root extension.
inline HRESULT UpdateRegistryForExt(UINT nResId, BOOL bRegister,
	const wchar_t* szRootExt, const wchar_t* szExtension) throw()
{
	_ATL_REGMAP_ENTRY regmapEntries[] = 
	{
		{L"EXTENSION", szExtension},
		{L"ROOTTYPE", szRootExt},
		{NULL, NULL}
	};

	return ATL::_pAtlModule->UpdateRegistryFromResource(nResId, bRegister, regmapEntries);
}


// All-in-one registration function for 1 extenstion, call 'ForExt' to register aditional functions.
inline HRESULT UpdateRegistry(UINT nResIdRoot, UINT nResIdExt, BOOL bRegister,
	const wchar_t* szDescription, const CLSID& clsid, const wchar_t* szRootExt, const wchar_t* szExtension) throw()
{
	// note: during unregistration try to unregister as much as possible.
	HRESULT hrFinal = S_OK;

	HRESULT hr = UpdateRegistryForRootExt(nResIdRoot, bRegister, szDescription, clsid, szRootExt);
	if (FAILED(hr))
		hrFinal = hr;

	hr = UpdateRegistryForExt(nResIdExt, bRegister, szRootExt, szExtension);
	if (FAILED(hr))
		hrFinal = hr;

	return hrFinal;
}


inline HRESULT UpdateRegistryFromResource(UINT nResId, BOOL bRegister,
	const wchar_t* szShellExtDescription, const CLSID& clsid, const CLSID& clsidShellFolder, const wchar_t* szExtension) throw()
{
	COleString olestrCLSID;
	COleString olestrClsidShellFolder;

	ATLVERIFY(SUCCEEDED(StringFromCLSID(clsid, olestrCLSID)));
	ATLVERIFY(SUCCEEDED(StringFromCLSID(clsidShellFolder, olestrClsidShellFolder)));

	_ATL_REGMAP_ENTRY regmapEntries[] =
	{
		{L"DESCRIPTION", szShellExtDescription},
		{L"EXTENSION", szExtension},
		{L"CLSID", olestrCLSID},
		{L"CLSIDSHELLFOLDER", olestrClsidShellFolder},
		{NULL, NULL}
	};

	return ATL::_pAtlModule->UpdateRegistryFromResource(nResId, bRegister, regmapEntries);
}


inline HRESULT UpdateRegistryFromResource(UINT nResId, BOOL bRegister,
	const wchar_t* szShellExtDescription, const CLSID& clsid, const wchar_t* szExtension, UINT nFriendlyTypeNameId) throw()
{
	COleString olestrCLSID;
	ATLVERIFY(SUCCEEDED(StringFromCLSID(clsid, olestrCLSID)));

	CStringW strFriendlyTypenameId = ToStringW(nFriendlyTypeNameId);

	_ATL_REGMAP_ENTRY regmapEntries[] =
	{
		{L"DESCRIPTION", szShellExtDescription},
		{L"EXTENSION", szExtension},
		{L"CLSID", olestrCLSID},
		{L"FRIENDLYTYPENAME", strFriendlyTypenameId},
		{NULL, NULL}
	};

	return ATL::_pAtlModule->UpdateRegistryFromResource(nResId, bRegister, regmapEntries);
}

} // namespace MSF

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Software Developer (Senior) Hitachi High-Tech Analytical Science
Netherlands Netherlands
Victor lives in Nijmegen, the oldest city in The Netherlands.
He studied Applied Physics in Delft and works Hitachi High-Tech Analytical Science.

Comments and Discussions