//
//	Class:		CResourceServerST
//
//	Compiler:	Visual C++
//	Tested on:	Visual C++ 5.0
//				Visual C++ 6.0
//				Visual C++ 2005
//
//	Version:	See GetVersionC() or GetVersionI()
//
//	Created:	26/August/1999
//	Updated:	27/October/2006
//
//	Author:		Davide Calabro'		info@softechsoftware.it
//									http://www.softechsoftware.it
//
//	Disclaimer
//	----------
//	THIS SOFTWARE AND THE ACCOMPANYING FILES ARE DISTRIBUTED "AS IS" AND WITHOUT
//	ANY WARRANTIES WHETHER EXPRESSED OR IMPLIED. NO REPONSIBILITIES FOR POSSIBLE
//	DAMAGES OR EVEN FUNCTIONALITY CAN BE TAKEN. THE USER MUST ASSUME THE ENTIRE
//	RISK OF USING THIS SOFTWARE.
//
//	Terms of use
//	------------
//	In the past years SoftechSoftware has produced many free controls and code snippets.
//	All of this products were released with the full source codes included and hundreds of developers
//	all around the world have taken benefits using these easy and ready to use controls into their applications.
//	In return, SoftechSoftware asked only for a small money donation from developers.
//	Unfortunately only a very limited number of donations has been received from the large number of users
//	that rely on SoftechSoftware products for their applications.
//	Producing and updating good software costs time. So it costs money. Also, maintaning a dedicated web site
//	costs time and money.
//
//	Starting from now on almost all SoftechSoftware products will be distributed into a single general use DLL.
//	This DLL will show an annoying dialog each time your application starts. Also, this demo DLL has resource
//	and memory leaks that make your target application unstable. You can use the demo DLL only for testing
//	the SoftechSoftware product you are interested in. Then if you decide to use this product into your
//	application you must buy the full DLL version directly from SoftechSoftware.
//
//	SoftechSoftware DLL costs €100.00 (One hundred Euros).
//
//		SoftechSoftware
//		Davide Calabro'
//		Italy
//
//		http://www.softechsoftware.it
//
#ifndef _RESOURCESERVERST_H_
#define _RESOURCESERVERST_H_

#if _MSC_VER >= 1000
#pragma once
#endif // _MSC_VER >= 1000

// Uncomment following line if you are using this class outside the DLL
//#define _RESOURCESERVERST_NODLL_

#ifndef _RESOURCESERVERST_NODLL_
#ifndef	_SOFTECHSOFTWAREDLL_NOLIB_
	#ifdef _DEBUG
		#ifdef _UNICODE
			#pragma comment(lib, "SoftechSoftwareUD.lib")
		#else
			#pragma comment(lib, "SoftechSoftwareD.lib")
		#endif
	#else
		#ifdef _UNICODE
			#pragma comment(lib, "SoftechSoftwareU.lib")
		#else
			#pragma comment(lib, "SoftechSoftware.lib")
		#endif
	#endif
#endif

	#ifdef	_SOFTECHSOFTWAREDLL_BUILDDLL_
		#define	RESOURCESERVERST_EXPORT	__declspec(dllexport)
	#else
		#define	RESOURCESERVERST_EXPORT	__declspec(dllimport)
	#endif

#else
		#define	RESOURCESERVERST_EXPORT
#endif

// Error codes
#define RESSRVST_OK						0
#define RESSRVST_NOINIT					1
#define RESSRVST_ALREADYINIT			2
#define RESSRVST_DLLNOTFOUND			3
#define RESSRVST_FREELIBRARYKO			4
#define RESSRVST_RESNOTFOUND			5
#define RESSRVST_INVALIDPTR				6

class RESOURCESERVERST_EXPORT CResourceServerST  
{
public:
	CResourceServerST(LPCTSTR lpszDllName = NULL, DWORD dwFlags = 0);
	virtual ~CResourceServerST();

	DWORD Load(LPCTSTR lpszDllName, DWORD dwFlags = 0);
	DWORD UnLoad();

	HANDLE LoadImage(LPCTSTR lpszName, UINT uType, int cxDesired, int cyDesired, UINT fuLoad);
	HANDLE LoadImage(UINT uID, UINT uType, int cxDesired, int cyDesired, UINT fuLoad);

	HICON LoadIcon(LPCTSTR lpszName, int nCxDesired = 0, int nCyDesired = 0);
	HICON LoadIcon(UINT uID, int nCxDesired = 0, int nCyDesired = 0);

	HBITMAP LoadBitmap(LPCTSTR lpszName, UINT fuLoad = 0);
	HBITMAP LoadBitmap(UINT uID, UINT fuLoad = 0);

	DWORD LoadString(UINT nID, LPTSTR lpBuffer, int nBufferMax);
	DWORD LoadString(UINT nID, CString* spBuffer);

	HRSRC FindResource(LPCTSTR lpName, LPCTSTR lpType);

	HGLOBAL LoadResource(LPCTSTR lpszName, LPCTSTR lpszType);
	HGLOBAL LoadResource(HRSRC hResInfo);

	HGLOBAL LoadDialog(UINT nID);
	
	DWORD GetLastError();

	static short GetVersionI()		{return 13;}
	static LPCTSTR GetVersionC()	{return (LPCTSTR)_T("1.3");}

private:
	DWORD SetLastError(DWORD dwError);

	DWORD				m_dwLastError;
	HINSTANCE			m_hDll;
	CRITICAL_SECTION	m_csWait;
};

#endif
