Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r84684 - in trunk: boost/thread/win32 libs/thread/src/win32
From: vicente.botet_at_[hidden]
Date: 2013-06-08 04:21:35


Author: viboes
Date: 2013-06-08 04:21:34 EDT (Sat, 08 Jun 2013)
New Revision: 84684
URL: http://svn.boost.org/trac/boost/changeset/84684

Log:
Thread: apply patch #8550.

Added:
   trunk/boost/thread/win32/mfc_thread_init.hpp (contents, props changed)
Text files modified:
   trunk/boost/thread/win32/mfc_thread_init.hpp | 41 ++++++++++++++++++++++++++++++++++++++++
   trunk/libs/thread/src/win32/tss_pe.cpp | 41 ++++++++++++++++++++++++++++++++++++++++
   2 files changed, 82 insertions(+), 0 deletions(-)

Added: trunk/boost/thread/win32/mfc_thread_init.hpp
==============================================================================
--- /dev/null 00:00:00 1970 (empty, because file is newly added)
+++ trunk/boost/thread/win32/mfc_thread_init.hpp 2013-06-08 04:21:34 EDT (Sat, 08 Jun 2013) (r84684)
@@ -0,0 +1,41 @@
+#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

Modified: trunk/libs/thread/src/win32/tss_pe.cpp
==============================================================================
--- trunk/libs/thread/src/win32/tss_pe.cpp Sat Jun 8 03:32:22 2013 (r84683)
+++ trunk/libs/thread/src/win32/tss_pe.cpp 2013-06-08 04:21:34 EDT (Sat, 08 Jun 2013) (r84684)
@@ -80,6 +80,36 @@
     #define WIN32_LEAN_AND_MEAN
     #include <windows.h>
 
+
+// _pRawDllMainOrig can be defined by including boost/thread/win32/mfc_thread_init.hpp
+// into your dll; it ensures that MFC-Dll-initialization will be done properly
+// The following code is adapted from the MFC-Dll-init code
+/*
+ * _pRawDllMainOrig MUST be an extern const variable, which will be aliased to
+ * _pDefaultRawDllMainOrig if no real user definition is present, thanks to the
+ * alternatename directive.
+ */
+
+// work at least with _MSC_VER 1500 (MSVC++ 9.0, VS 2008)
+#if (_MSC_VER >= 1500)
+
+extern "C" {
+extern BOOL (WINAPI * const _pRawDllMainOrig)(HANDLE, DWORD, LPVOID);
+extern BOOL (WINAPI * const _pDefaultRawDllMainOrig)(HANDLE, DWORD, LPVOID) = NULL;
+#if defined (_M_IX86)
+#pragma comment(linker, "/alternatename:__pRawDllMainOrig=__pDefaultRawDllMainOrig")
+#elif defined (_M_X64) || defined (_M_ARM)
+#pragma comment(linker, "/alternatename:_pRawDllMainOrig=_pDefaultRawDllMainOrig")
+#else /* defined (_M_X64) || defined (_M_ARM) */
+#error Unsupported platform
+#endif /* defined (_M_X64) || defined (_M_ARM) */
+}
+
+#endif
+
+
+
+
     //Definitions required by implementation
 
     #if (_MSC_VER < 1300) // 1300 == VC++ 7.0
@@ -240,7 +270,11 @@
             }
         }
 
+#if (_MSC_VER >= 1500)
+ BOOL WINAPI dll_callback(HANDLE hInstance, DWORD dwReason, LPVOID lpReserved)
+#else
         BOOL WINAPI dll_callback(HANDLE, DWORD dwReason, LPVOID)
+#endif
         {
             switch (dwReason)
             {
@@ -251,6 +285,13 @@
                 boost::on_process_exit();
                 break;
             }
+
+#if (_MSC_VER >= 1500)
+ if( _pRawDllMainOrig )
+ {
+ return _pRawDllMainOrig(hInstance, dwReason, lpReserved);
+ }
+#endif
             return true;
         }
     } //namespace


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk