Click here to Skip to main content
Click here to Skip to main content
Add your own
alternative version

Shell Extensions for .NET Assemblies

, 17 Nov 2005 Ms-PL
Shell extensions to distinguish between .NET assemblies and Win32 applications and libraries.
// rgsmap.h: Macros to extend variables in .rgs files.

#pragma once

#include <atlbase.h>
#include <strsafe.h>
#include <new>

struct _ATL_REGMAP_ENTRY_EX : public _ATL_REGMAP_ENTRY
{
	_ATL_REGMAP_ENTRY_EX()
	{
		szKey = NULL;
		szData = NULL;
	}

	_ATL_REGMAP_ENTRY_EX(LPCOLESTR szKey, LPCOLESTR szData)
	{
		size_t cchData;
		
		cchData = wcslen(szData);
		this->szData = new (std::nothrow) WCHAR[cchData + 1];
		if (this->szData)
		{
			this->szKey = szKey;
			StringCchCopyW((LPWSTR)this->szData, cchData + 1, szData);
		}
	}

	_ATL_REGMAP_ENTRY_EX(LPCOLESTR szKey, UINT uiResID)
	{
		TCHAR szRes[MAX_PATH];

		// Load the string using the current encoding.
		if (0 == LoadString(_pModule->GetResourceInstance(), uiResID,
			szRes, MAX_PATH))
		{
			szRes[0] = TEXT('\0');
		}

		// Convert the string and let the other ctor alloc and copy.
		_ATL_REGMAP_ENTRY_EX(szKey, (LPCOLESTR) CT2WEX<MAX_PATH>(szRes));
	}

	_ATL_REGMAP_ENTRY_EX(LPCOLESTR szKey, REFGUID refGUID)
	{
		LPOLESTR pszGUID;

		szData = LPCOLESTR(pszGUID = new (std::nothrow) WCHAR[40]);
		if (szData)
		{
			if (0 != StringFromGUID2(refGUID, pszGUID, 40))
			{
				this->szKey = szKey;
			}
		}
	}

	~_ATL_REGMAP_ENTRY_EX()
	{
		delete [] (LPOLESTR) szData;
	}
};

#define BEGIN_REGISTRY_MAP(cls) \
	static struct _ATL_REGMAP_ENTRY* GetRegistryMap() \
	{ \
		static const _ATL_REGMAP_ENTRY_EX rgRegMap[] = {

#define REGISTRY_ENTRY(k, v) _ATL_REGMAP_ENTRY_EX(OLESTR(##k), OLESTR(##v)),

#define REGISTRY_RESOURCE(k, resID) _ATL_REGMAP_ENTRY_EX(OLESTR(##k), (UINT)resID),

#define REGISTRY_GUID(k, guid) _ATL_REGMAP_ENTRY_EX(OLESTR(##k), (REFGUID)guid),

#define END_REGISTRY_MAP() _ATL_REGMAP_ENTRY_EX() }; \
		return (_ATL_REGMAP_ENTRY*) rgRegMap; \
	};

#define DECLARE_REGISTRY_RESOURCEID_EX(resID) \
	static HRESULT WINAPI UpdateRegistry(BOOL fRegister) \
	{ \
		return ATL::_pAtlModule->UpdateRegistryFromResource(resID, fRegister, GetRegistryMap()); \
	}

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, along with any associated source code and files, is licensed under The Microsoft Public License (Ms-PL)

Share

About the Author

Heath Stewart
Program Manager Microsoft
United States United States
Heath Stewart is a happily married software engineer originally from the Midwest and a graduate of Iowa State University. Heath start programming early in life and enjoys continuous research and development in new languages, frameworks, and platforms. Fluent in many different programming languages, he has developed many large-scale software solutions for companies in different areas, such as Internet filtering, intrusion detection systems, production management systems, and web applications for various purposes. He also enjoys photography.
 
Currently, Heath is a Program Manager in the Visual Studio Professional Deployment Experience (VSPro DEX) team at Microsoft. Previous to his employment, he was a Microsoft MVP for Visual C#.
 
He is also a CodeProject protector and is happy to help the development community.
Follow on   Twitter

| Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.141223.1 | Last Updated 17 Nov 2005
Article Copyright 2002 by Heath Stewart
Everything else Copyright © CodeProject, 1999-2014
Layout: fixed | fluid