Ticket #8550: mfc_dll_thread.patch
File mfc_dll_thread.patch, 3.6 KB (added by , 9 years ago) |
---|
-
libs/thread/src/win32/tss_pe.cpp
80 80 #define WIN32_LEAN_AND_MEAN 81 81 #include <windows.h> 82 82 83 84 // _pRawDllMainOrig can be defined by including boost/thread/win32/mfc_thread_init.hpp 85 // into your dll; it ensures that MFC-Dll-initialization will be done properly 86 // The following code is adapted from the MFC-Dll-init code 87 /* 88 * _pRawDllMainOrig MUST be an extern const variable, which will be aliased to 89 * _pDefaultRawDllMainOrig if no real user definition is present, thanks to the 90 * alternatename directive. 91 */ 92 93 // work at least with _MSC_VER 1500 (MSVC++ 9.0, VS 2008) 94 #if (_MSC_VER >= 1500) 95 96 extern "C" { 97 extern BOOL (WINAPI * const _pRawDllMainOrig)(HANDLE, DWORD, LPVOID); 98 extern BOOL (WINAPI * const _pDefaultRawDllMainOrig)(HANDLE, DWORD, LPVOID) = NULL; 99 #if defined (_M_IX86) 100 #pragma comment(linker, "/alternatename:__pRawDllMainOrig=__pDefaultRawDllMainOrig") 101 #elif defined (_M_X64) || defined (_M_ARM) 102 #pragma comment(linker, "/alternatename:_pRawDllMainOrig=_pDefaultRawDllMainOrig") 103 #else /* defined (_M_X64) || defined (_M_ARM) */ 104 #error Unsupported platform 105 #endif /* defined (_M_X64) || defined (_M_ARM) */ 106 } 107 108 #endif 109 110 111 112 83 113 //Definitions required by implementation 84 114 85 115 #if (_MSC_VER < 1300) // 1300 == VC++ 7.0 … … 240 270 } 241 271 } 242 272 273 #if (_MSC_VER >= 1500) 274 BOOL WINAPI dll_callback(HANDLE hInstance, DWORD dwReason, LPVOID lpReserved) 275 #else 243 276 BOOL WINAPI dll_callback(HANDLE, DWORD dwReason, LPVOID) 277 #endif 244 278 { 245 279 switch (dwReason) 246 280 { … … 251 285 boost::on_process_exit(); 252 286 break; 253 287 } 288 289 #if (_MSC_VER >= 1500) 290 if( _pRawDllMainOrig ) 291 { 292 return _pRawDllMainOrig(hInstance, dwReason, lpReserved); 293 } 294 #endif 254 295 return true; 255 296 } 256 297 } //namespace -
boost/thread/win32/mfc_thread_init.hpp
1 #ifndef BOOST_THREAD_WIN32_MFC_THREAD_INIT_HPP 2 #define BOOST_THREAD_WIN32_MFC_THREAD_INIT_HPP 3 // Distributed under the Boost Software License, Version 1.0. (See 4 // accompanying file LICENSE_1_0.txt or copy at 5 // http://www.boost.org/LICENSE_1_0.txt) 6 // (C) Copyright 2008 Anthony Williams 7 // (C) Copyright 2011-2012 Vicente J. Botet Escriba 8 9 10 // check if we use MFC 11 #ifdef _AFXDLL 12 # if defined(_AFXEXT) 13 14 // can't use ExtRawDllMain from afxdllx.h as it also defines the symbol _pRawDllMain 15 extern "C" 16 inline BOOL WINAPI ExtRawDllMain(HINSTANCE, DWORD dwReason, LPVOID) 17 { 18 if (dwReason == DLL_PROCESS_ATTACH) 19 { 20 // save critical data pointers before running the constructors 21 AFX_MODULE_STATE* pModuleState = AfxGetModuleState(); 22 pModuleState->m_pClassInit = pModuleState->m_classList; 23 pModuleState->m_pFactoryInit = pModuleState->m_factoryList; 24 pModuleState->m_classList.m_pHead = NULL; 25 pModuleState->m_factoryList.m_pHead = NULL; 26 } 27 return TRUE; // ok 28 } 29 30 extern "C" __declspec(selectany) BOOL (WINAPI * const _pRawDllMainOrig)(HANDLE, DWORD, LPVOID) = &ExtRawDllMain; 31 32 # elif defined(_USRDLL) 33 34 extern "C" BOOL WINAPI RawDllMain(HANDLE, DWORD dwReason, LPVOID); 35 extern "C" __declspec(selectany) BOOL (WINAPI * const _pRawDllMainOrig)(HANDLE, DWORD, LPVOID) = &RawDllMain; 36 37 # endif 38 #endif 39 40 41 #endif