4 * Copyright 2009 Andrew Hill <ash77@reactos.org>
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.
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.
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
25 #define WIN32_NO_STATUS
27 #define COM_NO_WINDOWS_H
38 #define ATLASSERT(expr) _ASSERTE(expr)
44 class CComCriticalSection
47 CRITICAL_SECTION m_sec
;
51 memset(&m_sec
, 0, sizeof(CRITICAL_SECTION
));
54 virtual ~CComCriticalSection()
60 EnterCriticalSection(&m_sec
);
66 LeaveCriticalSection(&m_sec
);
72 InitializeCriticalSection(&m_sec
);
78 DeleteCriticalSection(&m_sec
);
83 class CComFakeCriticalSection
107 class CComAutoCriticalSection
: public CComCriticalSection
110 CComAutoCriticalSection()
112 HRESULT hResult __MINGW_ATTRIB_UNUSED
;
114 hResult
= CComCriticalSection::Init();
115 ATLASSERT(SUCCEEDED(hResult
));
117 ~CComAutoCriticalSection()
119 CComCriticalSection::Term();
123 class CComSafeDeleteCriticalSection
: public CComCriticalSection
128 CComSafeDeleteCriticalSection()
130 m_bInitialized
= false;
133 ~CComSafeDeleteCriticalSection()
140 ATLASSERT(m_bInitialized
);
141 return CComCriticalSection::Lock();
148 ATLASSERT(!m_bInitialized
);
149 hResult
= CComCriticalSection::Init();
150 if (SUCCEEDED(hResult
))
151 m_bInitialized
= true;
159 m_bInitialized
= false;
160 return CComCriticalSection::Term();
164 class CComAutoDeleteCriticalSection
: public CComSafeDeleteCriticalSection
167 // CComAutoDeleteCriticalSection::Term should never be called
171 struct _ATL_BASE_MODULE70
175 HINSTANCE m_hInstResource
;
179 CRITICAL_SECTION m_csResource
;
181 CSimpleArray
<HINSTANCE
> m_rgResourceInstance
;
184 typedef _ATL_BASE_MODULE70 _ATL_BASE_MODULE
;
186 class CAtlBaseModule
: public _ATL_BASE_MODULE
189 static bool m_bInitFailed
;
193 cbSize
= sizeof(_ATL_BASE_MODULE
);
194 GetModuleHandleExW(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS
, (LPCWSTR
)this, &m_hInst
);
195 m_hInstResource
= m_hInst
;
198 HINSTANCE
GetModuleInstance()
203 HINSTANCE
GetResourceInstance()
205 return m_hInstResource
;
209 extern CAtlBaseModule _AtlBaseModule
;