ReactOS  0.4.14-dev-115-g4576127
atlcore.h
Go to the documentation of this file.
1 /*
2  * ReactOS ATL
3  *
4  * Copyright 2009 Andrew Hill <ash77@reactos.org>
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19  */
20 
21 #pragma once
22 
23 #include <malloc.h>
24 
25 #ifdef __REACTOS__
26  #define WIN32_NO_STATUS
27  #define _INC_WINDOWS
28  #define COM_NO_WINDOWS_H
29  #include <stdarg.h>
30  #include <windef.h>
31  #include <winbase.h>
32  #include <winreg.h>
33  #include <winnls.h>
34 #else
35  #include <windows.h>
36 #endif
37 #include <ole2.h>
38 #include <olectl.h>
39 #include <crtdbg.h>
40 
41 #ifndef ATLASSERT
42 #define ATLASSERT(expr) _ASSERTE(expr)
43 #endif // ATLASSERT
44 
45 namespace ATL
46 {
47 
49 {
50 public:
52 public:
54  {
55  memset(&m_sec, 0, sizeof(CRITICAL_SECTION));
56  }
57 
59  {
60  }
61 
63  {
65  return S_OK;
66  }
67 
69  {
71  return S_OK;
72  }
73 
75  {
77  return S_OK;
78  }
79 
81  {
83  return S_OK;
84  }
85 };
86 
88 {
89 public:
91  {
92  return S_OK;
93  }
94 
96  {
97  return S_OK;
98  }
99 
101  {
102  return S_OK;
103  }
104 
106  {
107  return S_OK;
108  }
109 };
110 
112 {
113 public:
115  {
117 
118  hResult = CComCriticalSection::Init();
119  ATLASSERT(SUCCEEDED(hResult));
120  }
122  {
124  }
125 };
126 
128 {
129 private:
131 public:
133  {
134  m_bInitialized = false;
135  }
136 
138  {
139  Term();
140  }
141 
143  {
145  return CComCriticalSection::Lock();
146  }
147 
149  {
150  HRESULT hResult;
151 
153  hResult = CComCriticalSection::Init();
154  if (SUCCEEDED(hResult))
155  m_bInitialized = true;
156  return hResult;
157  }
158 
160  {
161  if (!m_bInitialized)
162  return S_OK;
163  m_bInitialized = false;
164  return CComCriticalSection::Term();
165  }
166 };
167 
169 {
170 private:
171  // CComAutoDeleteCriticalSection::Term should never be called
172  HRESULT Term();
173 };
174 
176 {
184 #ifdef NOTYET
185  CSimpleArray<HINSTANCE> m_rgResourceInstance;
186 #endif
187 };
189 
191 {
192 public :
193  static bool m_bInitFailed;
194 public:
196  {
197  cbSize = sizeof(_ATL_BASE_MODULE);
198  GetModuleHandleExW(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS, (LPCWSTR)this, &m_hInst);
200  }
201 
203  {
204  return m_hInst;
205  }
206 
208  {
209  return m_hInstResource;
210  }
211 
213  {
214  return static_cast< HINSTANCE >(InterlockedExchangePointer((void**)&m_hInstResource, hInst));
215  }
216 
218 };
219 
220 __declspec(selectany) CAtlBaseModule _AtlBaseModule;
221 __declspec(selectany) bool CAtlBaseModule::m_bInitFailed = false;
222 
223 
225 // String Resource helper functions
226 //
227 #ifdef _MSC_VER
228 #pragma warning(push)
229 #pragma warning(disable:4200)
230 #endif
232 {
235 };
236 #ifdef _MSC_VER
237 #pragma warning(pop)
238 #endif
239 
242  _In_ HRSRC hResource,
243  _In_ UINT id)
244 {
245  const ATLSTRINGRESOURCEIMAGE* pImage;
246  const ATLSTRINGRESOURCEIMAGE* pImageEnd;
247  ULONG nResourceSize;
248  HGLOBAL hGlobal;
249  UINT iIndex;
250 
251  hGlobal = ::LoadResource(hInstance, hResource);
252  if (hGlobal == NULL) return NULL;
253 
254  pImage = (const ATLSTRINGRESOURCEIMAGE*)::LockResource(hGlobal);
255  if (pImage == NULL) return NULL;
256 
257  nResourceSize = ::SizeofResource(hInstance, hResource);
258  pImageEnd = (const ATLSTRINGRESOURCEIMAGE*)(LPBYTE(pImage) + nResourceSize);
259  iIndex = id & 0x000f;
260 
261  while ((iIndex > 0) && (pImage < pImageEnd))
262  {
263  pImage = (const ATLSTRINGRESOURCEIMAGE*)(LPBYTE(pImage) + (sizeof(ATLSTRINGRESOURCEIMAGE) + (pImage->nLength * sizeof(WCHAR))));
264  iIndex--;
265  }
266 
267  if (pImage >= pImageEnd) return NULL;
268  if (pImage->nLength == 0) return NULL;
269 
270  return pImage;
271 }
272 
275  _In_ UINT id) throw()
276 {
277  HRSRC hResource;
278  hResource = ::FindResourceW(hInstance, MAKEINTRESOURCEW((((id >> 4) + 1) & static_cast<WORD>(~0))), (LPWSTR)RT_STRING);
279  if (hResource == NULL) return NULL;
280  return _AtlGetStringResourceImage(hInstance, hResource, id);
281 }
282 
285  _In_ UINT id,
286  _In_ WORD wLanguage)
287 {
288  HRSRC hResource;
289  hResource = ::FindResourceExW(hInstance, (LPWSTR)RT_STRING, MAKEINTRESOURCEW((((id >> 4) + 1) & static_cast<WORD>(~0))), wLanguage);
290  if (hResource == NULL) return NULL;
291  return _AtlGetStringResourceImage(hInstance, hResource, id);
292 }
293 
295  UINT nID,
296  WORD wLanguage = 0)
297 {
298  const ATLSTRINGRESOURCEIMAGE* strRes = NULL;
299  HINSTANCE hInst = _AtlBaseModule.GetHInstanceAt(0);
300 
301  for (int i = 1; hInst != NULL && strRes == NULL; hInst = _AtlBaseModule.GetHInstanceAt(i++))
302  {
303  strRes = AtlGetStringResourceImage(hInst, nID, wLanguage);
304  if (strRes != NULL) return hInst;
305  }
306 
307  return NULL;
308 }
309 
310 }; // namespace ATL
HINSTANCE GetModuleInstance()
Definition: atlcore.h:202
HINSTANCE SetResourceInstance(HINSTANCE hInst)
Definition: atlcore.h:212
const WCHAR * LPCWSTR
Definition: xmlstorage.h:185
CRITICAL_SECTION m_csResource
Definition: atlcore.h:183
LPVOID WINAPI LockResource(HGLOBAL handle)
Definition: res.c:550
void WINAPI EnterCriticalSection(LPCRITICAL_SECTION)
const ATLSTRINGRESOURCEIMAGE * AtlGetStringResourceImage(_In_ HINSTANCE hInstance, _In_ UINT id)
Definition: atlcore.h:273
HRSRC WINAPI FindResourceW(HINSTANCE hModule, LPCWSTR name, LPCWSTR type)
Definition: res.c:176
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
HINSTANCE hInstance
Definition: charmap.c:20
unsigned char * LPBYTE
Definition: typedefs.h:52
HGLOBAL WINAPI LoadResource(HINSTANCE hModule, HRSRC hRsrc)
Definition: res.c:532
VOID WINAPI InitializeCriticalSection(OUT LPCRITICAL_SECTION lpCriticalSection)
Definition: synch.c:751
smooth NULL
Definition: ftsmooth.c:416
HINSTANCE GetResourceInstance()
Definition: atlcore.h:207
#define ATLASSERT(expr)
Definition: atlcore.h:42
Definition: rosdlgs.h:5
HINSTANCE GetHInstanceAt(int i)
#define InterlockedExchangePointer(Target, Value)
Definition: dshow.h:45
HINSTANCE AtlFindStringResourceInstance(UINT nID, WORD wLanguage=0)
Definition: atlcore.h:294
__wchar_t WCHAR
Definition: xmlstorage.h:180
void WINAPI DeleteCriticalSection(PCRITICAL_SECTION)
LONG HRESULT
Definition: typedefs.h:77
unsigned short WORD
Definition: ntddk_ex.h:93
unsigned long DWORD
Definition: ntddk_ex.h:95
#define __MINGW_ATTRIB_UNUSED
Definition: _mingw.h:122
HRSRC WINAPI FindResourceExW(HMODULE hModule, LPCWSTR type, LPCWSTR name, WORD lang)
Definition: res.c:164
#define RT_STRING
Definition: pedump.c:368
#define _In_
Definition: no_sal2.h:204
CRITICAL_SECTION m_sec
Definition: atlcore.h:51
virtual ~CComCriticalSection()
Definition: atlcore.h:58
BOOL WINAPI GetModuleHandleExW(IN DWORD dwFlags, IN LPCWSTR lpwModuleName OPTIONAL, OUT HMODULE *phModule)
Definition: loader.c:875
#define S_OK
Definition: intsafe.h:59
HINSTANCE hInst
Definition: dxdiag.c:13
_ATL_BASE_MODULE70 _ATL_BASE_MODULE
Definition: atlcore.h:188
unsigned int UINT
Definition: ndis.h:50
DWORD WINAPI SizeofResource(HINSTANCE hModule, HRSRC hRsrc)
Definition: res.c:568
HINSTANCE m_hInstResource
Definition: atlcore.h:179
__declspec(selectany) CAtlModule *_pAtlModule
Definition: atlbase.h:525
const ATLSTRINGRESOURCEIMAGE * _AtlGetStringResourceImage(_In_ HINSTANCE hInstance, _In_ HRSRC hResource, _In_ UINT id)
Definition: atlcore.h:240
unsigned int ULONG
Definition: retypes.h:1
#define MAKEINTRESOURCEW(i)
Definition: winuser.h:582
void WINAPI LeaveCriticalSection(LPCRITICAL_SECTION)
WCHAR * LPWSTR
Definition: xmlstorage.h:184
#define memset(x, y, z)
Definition: compat.h:39
static bool m_bInitFailed
Definition: atlcore.h:193
#define SUCCEEDED(hr)
Definition: intsafe.h:57