[atlnew]
authorAndrew Hill <ash77@reactos.org>
Sat, 31 Oct 2009 23:40:09 +0000 (23:40 +0000)
committerAndrew Hill <ash77@reactos.org>
Sat, 31 Oct 2009 23:40:09 +0000 (23:40 +0000)
- RosBE doesn't support __ImageBase, so use GetModuleHandleExW(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS) instead.
- Implement CAtlBaseModule constructor.
[browseui]
- Since RosBE built DLLs don't run global constructors, use placement new to construct them in DllMain. This is a *HACK* and a better solution should be found.
- Change DllMain be be extern C so it actually gets used.

svn path=/trunk/; revision=43890

reactos/dll/win32/browseui/browseui.cpp
reactos/lib/atl/atlbase.h
reactos/lib/atl/atlcore.h

index fc92d8e..ed547b0 100644 (file)
@@ -61,12 +61,23 @@ END_OBJECT_MAP()
 CBrowseUIModule                                                                gModule;
 CAtlWinModule                                                          gWinModule;
 
+void *operator new (size_t, void *buf)
+{
+       return buf;
+}
+
 /*************************************************************************
  * BROWSEUI DllMain
  */
-BOOL WINAPI DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID fImpLoad)
+STDAPI_(BOOL) DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID fImpLoad)
 {
     TRACE("%p 0x%x %p\n", hInstance, dwReason, fImpLoad);
+       
+       /* HACK - the global constructors don't run, so I placement new them here */
+       new (&gModule) CBrowseUIModule;
+       new (&gWinModule) CAtlWinModule;
+       new (&_AtlBaseModule) CAtlBaseModule;
+
        if (dwReason == DLL_PROCESS_ATTACH)
        {
                gModule.Init(ObjectMap, hInstance, NULL);
index a37516c..1cce797 100644 (file)
@@ -53,8 +53,6 @@
 
 #define offsetofclass(base, derived) (reinterpret_cast<DWORD_PTR>(static_cast<base *>(reinterpret_cast<derived *>(_ATL_PACKING))) - _ATL_PACKING)
 
-extern "C" IMAGE_DOS_HEADER __ImageBase;
-
 namespace ATL
 {
 
@@ -451,7 +449,7 @@ class CAtlComModule : public _ATL_COM_MODULE
 public:
        CAtlComModule()
        {
-               m_hInstTypeLib = reinterpret_cast<HINSTANCE>(&__ImageBase);
+               GetModuleHandleExW(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS, (LPCWSTR)this, &m_hInstTypeLib);
                m_ppAutoObjMapFirst = NULL;
                m_ppAutoObjMapLast = NULL;
                if (FAILED(m_csObjMap.Init()))
index 2154241..55fcfe5 100644 (file)
@@ -181,6 +181,13 @@ class CAtlBaseModule : public _ATL_BASE_MODULE
 public :
        static bool                                                             m_bInitFailed;
 public:
+       CAtlBaseModule()
+       {
+               cbSize = sizeof(_ATL_BASE_MODULE);
+               GetModuleHandleExW(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS, (LPCWSTR)this, &m_hInst);
+               m_hInstResource = m_hInst;
+       }
+
        HINSTANCE GetModuleInstance()
        {
                return m_hInst;