| 1 | /* $Id: windllbase.h,v 1.7 2000-03-04 19:51:13 sandervl Exp $ */
 | 
|---|
| 2 | 
 | 
|---|
| 3 | /*
 | 
|---|
| 4 |  * Win32 Dll base class
 | 
|---|
| 5 |  *
 | 
|---|
| 6 |  * Copyright 1998-1999 Sander van Leeuwen (sandervl@xs4all.nl)
 | 
|---|
| 7 |  *
 | 
|---|
| 8 |  *
 | 
|---|
| 9 |  * Project Odin Software License can be found in LICENSE.TXT
 | 
|---|
| 10 |  *
 | 
|---|
| 11 |  */
 | 
|---|
| 12 | #ifndef __WINDLLBASE_H__
 | 
|---|
| 13 | #define __WINDLLBASE_H__
 | 
|---|
| 14 | 
 | 
|---|
| 15 | #include <winimagebase.h>
 | 
|---|
| 16 | #include <odinlx.h>
 | 
|---|
| 17 | 
 | 
|---|
| 18 | #ifndef HINSTANCE
 | 
|---|
| 19 | #define HINSTANCE ULONG
 | 
|---|
| 20 | #endif
 | 
|---|
| 21 | 
 | 
|---|
| 22 | #define DLL_PROCESS_ATTACH 1
 | 
|---|
| 23 | #define DLL_THREAD_ATTACH  2
 | 
|---|
| 24 | #define DLL_THREAD_DETACH  3
 | 
|---|
| 25 | #define DLL_PROCESS_DETACH 0
 | 
|---|
| 26 | 
 | 
|---|
| 27 | #define DONT_RESOLVE_DLL_REFERENCES     0x00000001
 | 
|---|
| 28 | #define LOAD_LIBRARY_AS_DATAFILE        0x00000002
 | 
|---|
| 29 | #define LOAD_WITH_ALTERED_SEARCH_PATH   0x00000008
 | 
|---|
| 30 | 
 | 
|---|
| 31 | //odin.ini section names to lookup renamed dlls
 | 
|---|
| 32 | //i.e. OLE32 -> OLE32OS2
 | 
|---|
| 33 | #define DLLRENAMEWIN_SECTION    "DLLRENAMEWIN"
 | 
|---|
| 34 | //i.e. OLE32OS2 -> OLE32
 | 
|---|
| 35 | #define DLLRENAMEOS2_SECTION    "DLLRENAMEOS2"
 | 
|---|
| 36 | 
 | 
|---|
| 37 | class Win32DllBase : public virtual Win32ImageBase
 | 
|---|
| 38 | {
 | 
|---|
| 39 | public:
 | 
|---|
| 40 |                   Win32DllBase(HINSTANCE hInstance, WIN32DLLENTRY DllEntryPoint, Win32ImageBase *parent = NULL);
 | 
|---|
| 41 | virtual          ~Win32DllBase();
 | 
|---|
| 42 | 
 | 
|---|
| 43 |         ULONG     AddRef()           { return ++referenced; };
 | 
|---|
| 44 |         //ASSUMPTION: called by FreeLibrary only
 | 
|---|
| 45 | virtual ULONG     Release();
 | 
|---|
| 46 |         char     *getName()          { return szModule; };
 | 
|---|
| 47 |         void      setNoEntryCalls()  { fSkipEntryCalls = TRUE; };
 | 
|---|
| 48 | 
 | 
|---|
| 49 |         Win32DllBase *getNext()  { return next; };
 | 
|---|
| 50 | static  Win32DllBase *getFirst();
 | 
|---|
| 51 | 
 | 
|---|
| 52 | //Send DLL_THREAD_ATTACH message to all dlls for a new thread
 | 
|---|
| 53 | static  void      attachThreadToAllDlls();
 | 
|---|
| 54 | 
 | 
|---|
| 55 | //Send DLL_THREAD_DETACH message to all dlls for thread that's about to die
 | 
|---|
| 56 | static  void      detachThreadFromAllDlls();
 | 
|---|
| 57 | 
 | 
|---|
| 58 | //Setup TLS structure for all dlls for a new thread
 | 
|---|
| 59 | static  void      tlsAttachThreadToAllDlls();
 | 
|---|
| 60 | 
 | 
|---|
| 61 | //Destroy TLS structure for all dlls for a thread that's about to die
 | 
|---|
| 62 | static  void      tlsDetachThreadFromAllDlls();
 | 
|---|
| 63 | 
 | 
|---|
| 64 |         BOOL      attachProcess();
 | 
|---|
| 65 |         BOOL      detachProcess();
 | 
|---|
| 66 |         BOOL      attachThread();
 | 
|---|
| 67 |         BOOL      detachThread();
 | 
|---|
| 68 | 
 | 
|---|
| 69 | // enable / disable thread attach/detach calls
 | 
|---|
| 70 |         void      setThreadLibraryCalls(BOOL fEnable);
 | 
|---|
| 71 | 
 | 
|---|
| 72 |         void      SetDynamicallyLoaded() { fDynamicLoad = TRUE; };
 | 
|---|
| 73 | 
 | 
|---|
| 74 | static  void      deleteAll(BOOL fDynamicLoad = FALSE);
 | 
|---|
| 75 | 
 | 
|---|
| 76 | static  BOOL      isSystemDll(char *szFileName);
 | 
|---|
| 77 | 
 | 
|---|
| 78 | virtual BOOL      isLxDll() = 0;
 | 
|---|
| 79 | virtual BOOL      isDll();
 | 
|---|
| 80 | 
 | 
|---|
| 81 | static  void      renameDll(char *dllname, BOOL fWinToOS2=TRUE);
 | 
|---|
| 82 | static  void      setDefaultRenaming();
 | 
|---|
| 83 | 
 | 
|---|
| 84 | static  Win32DllBase *findModule(char *dllname);
 | 
|---|
| 85 | static  Win32DllBase *findModule(HINSTANCE hinstance);
 | 
|---|
| 86 | static  Win32DllBase *findModule(WIN32DLLENTRY DllEntryPoint);
 | 
|---|
| 87 | 
 | 
|---|
| 88 | protected:
 | 
|---|
| 89 |         BOOL          fSkipEntryCalls, fUnloaded, fAttachedToProcess;
 | 
|---|
| 90 | 
 | 
|---|
| 91 |         WIN32DLLENTRY dllEntryPoint;
 | 
|---|
| 92 | 
 | 
|---|
| 93 |         ULONG         referenced;
 | 
|---|
| 94 | 
 | 
|---|
| 95 |         BOOL          fDynamicLoad;
 | 
|---|
| 96 | 
 | 
|---|
| 97 | private:
 | 
|---|
| 98 | static  Win32DllBase *head;
 | 
|---|
| 99 |         Win32DllBase *next;
 | 
|---|
| 100 | };
 | 
|---|
| 101 | 
 | 
|---|
| 102 | #endif
 | 
|---|