|
///////////////////////////////////////////////////////////////
//
// RcUtils.h
//
// Created: 23/09/2003
// Copyright (c) 2003 Ralph Hare (ralph.hare@ysgyfarnog.co.uk)
// All rights reserved.
//
// The code and information is provided "as-is" without
// warranty of any kind, either expressed or implied.
//
///////////////////////////////////////////////////////////////
#ifndef __RCUTILS_H_CD7115FD_F160_4393_9A07_E2FA49907F5C_
#define __RCUTILS_H_CD7115FD_F160_4393_9A07_E2FA49907F5C_
/**
* Class to extract a resource from a module and provide
* access it to as a templated type
**/
template< typename T >
class ResourceLoader
{
public:
ResourceLoader( HMODULE module, LPCTSTR name, LPCTSTR type ) :
m_module( module ),
m_resourceInfo( NULL ),
m_resource( NULL ),
m_pResource( NULL )
{
m_resourceInfo = ::FindResource( m_module, name, type );
if( m_resourceInfo == NULL )
{
throw std::exception( "Could not find resource" );
}
m_resource = ::LoadResource( m_module, m_resourceInfo );
if( m_resource == NULL )
{
throw std::exception( "Could not load resource" );
}
//
// no need to unlock resource
//
m_pResource = ::LockResource( m_resource );
if( m_pResource == NULL )
{
throw std::exception( "Could not lock resource" );
}
}
~ResourceLoader()
{
if( m_resource )
{
::FreeResource( m_resource );
}
}
operator T ()
{
return * reinterpret_cast< T * >( m_pResource );
}
operator T * ()
{
return reinterpret_cast< T * >( m_pResource );
}
size_t Size() const
{
return SizeofResource( m_module, m_resourceInfo );
}
private:
HMODULE m_module;
HRSRC m_resourceInfo;
HGLOBAL m_resource;
void *m_pResource;
};
#endif // __RCUTILS_H_CD7115FD_F160_4393_9A07_E2FA49907F5C_
|
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.
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
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.