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

Shell Extensions for .NET Assemblies

, 17 Nov 2005
Shell extensions to distinguish between .NET assemblies and Win32 applications and libraries.
// Resources.h : Resource management and related classes.

#pragma once

#include "stdafx.h"
#include <map>
#include <windows.h>

class CCriticalSection
{
public:

	// Default to the high-order WORD set, which on Win2K
	// pre-allocates the critical section. Default spin
	// count to 1024.
	CCriticalSection()
	{
		CCriticalSection(0x80000400);
	}

	// Pre-allocate a new critical section, using the spin
	// count to wait until the critical section can be created.
	CCriticalSection(DWORD dwSpinCount) :
		m_uiLockCount(0)
	{
		if (!InitializeCriticalSectionAndSpinCount(&m_cs, dwSpinCount))
			throw E_OUTOFMEMORY;
	}

	// Delete the critical section.
	~CCriticalSection() throw()
	{
		// It is the caller's responsibility to call
		// unlock enough times from the owning thread
		// before this object is destroyed.
		DeleteCriticalSection(&m_cs);
	}

	// Lock the critical section in the calling thread. This
	// will block if it is owned by one thread and attempting
	// to be locked by others.
	void Lock() throw()
	{
		EnterCriticalSection(&m_cs);
		m_uiLockCount++;
	}

	// Unlock the critical section by the owning calling thread.
	// Unlock should be called an equal number of times as Lock.
	// See get_LockCount to determine how many times to unlock.
	void Unlock() throw()
	{
		// Don't unlock more times than we've locked.
		if (m_uiLockCount)
		{
			m_uiLockCount--;
			LeaveCriticalSection(&m_cs);
		}
	}

	// Gets the net number of times Lock and Unlock were called.
	UINT get_LockCount()
	{
		return m_uiLockCount;
	}

private:

	CRITICAL_SECTION m_cs;
	UINT m_uiLockCount;
};

// TODO: Finish System.Resources.ResourceManager-like implementation.
class CResources
{
public:

	CResources() throw();
	LANGID GetCurrentUILanguage() throw();
	UINT LoadString(UINT uID, LPTSTR pszBuffer, UINT cchBuffer);

private:

	std::map<LCID, HINSTANCE> m_ResourceInstances;
	CCriticalSection m_cs;
};

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 | Mobile
Web04 | 2.8.140916.1 | Last Updated 17 Nov 2005
Article Copyright 2002 by Heath Stewart
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid