|
// 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.
Principal Software Engineer currently working on Azure SDKs at Microsoft. My opinions are my own. I work on a number of OSS projects for work and personally in numerous languages including C++, C#, JavaScript, Go, Rust, et. al. See a problem, fix a problem (or at least create an issue)!
Avid outdoor adventurer 🏔️❄️👞🚴♂️, husband, father.