| 1 | /* $Id: windllbase.h,v 1.6 1999-12-13 21:04:58 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 | static  void      deleteAll(); | 
|---|
| 73 |  | 
|---|
| 74 | static  BOOL      isSystemDll(char *szFileName); | 
|---|
| 75 |  | 
|---|
| 76 | virtual BOOL      isLxDll() = 0; | 
|---|
| 77 | virtual BOOL      isDll(); | 
|---|
| 78 |  | 
|---|
| 79 | static  void      renameDll(char *dllname, BOOL fWinToOS2=TRUE); | 
|---|
| 80 | static  void      setDefaultRenaming(); | 
|---|
| 81 |  | 
|---|
| 82 | static  Win32DllBase *findModule(char *dllname); | 
|---|
| 83 | static  Win32DllBase *findModule(HINSTANCE hinstance); | 
|---|
| 84 | static  Win32DllBase *findModule(WIN32DLLENTRY DllEntryPoint); | 
|---|
| 85 |  | 
|---|
| 86 | protected: | 
|---|
| 87 | BOOL          fSkipEntryCalls, fUnloaded, fAttachedToProcess; | 
|---|
| 88 |  | 
|---|
| 89 | WIN32DLLENTRY dllEntryPoint; | 
|---|
| 90 |  | 
|---|
| 91 | ULONG         referenced; | 
|---|
| 92 |  | 
|---|
| 93 | private: | 
|---|
| 94 | static  Win32DllBase *head; | 
|---|
| 95 | Win32DllBase *next; | 
|---|
| 96 | }; | 
|---|
| 97 |  | 
|---|
| 98 | #endif | 
|---|