summaryrefslogtreecommitdiff
path: root/boost/thread/win32/mfc_thread_init.hpp
blob: e866f8949f51c3f7cd37d5ceb963bce539a511c8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#ifndef BOOST_THREAD_WIN32_MFC_THREAD_INIT_HPP
#define BOOST_THREAD_WIN32_MFC_THREAD_INIT_HPP
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
// (C) Copyright 2008 Anthony Williams
// (C) Copyright 2011-2012 Vicente J. Botet Escriba


// check if we use MFC
#ifdef _AFXDLL
# if defined(_AFXEXT)

// can't use ExtRawDllMain from afxdllx.h as it also defines the symbol _pRawDllMain
extern "C"
inline BOOL WINAPI ExtRawDllMain(HINSTANCE, DWORD dwReason, LPVOID)
{
  if (dwReason == DLL_PROCESS_ATTACH)
  {
    // save critical data pointers before running the constructors
    AFX_MODULE_STATE* pModuleState = AfxGetModuleState();
    pModuleState->m_pClassInit = pModuleState->m_classList;
    pModuleState->m_pFactoryInit = pModuleState->m_factoryList;
    pModuleState->m_classList.m_pHead = NULL;
    pModuleState->m_factoryList.m_pHead = NULL;
  }
  return TRUE; // ok
}

extern "C" __declspec(selectany) BOOL (WINAPI * const _pRawDllMainOrig)(HANDLE, DWORD, LPVOID) = &ExtRawDllMain;

# elif defined(_USRDLL)

extern "C" BOOL WINAPI RawDllMain(HANDLE, DWORD dwReason, LPVOID);
extern "C" __declspec(selectany) BOOL (WINAPI * const _pRawDllMainOrig)(HANDLE, DWORD, LPVOID) = &RawDllMain;

# endif
#endif

#endif