| 1 | /* $Id: windllbase.h,v 1.2 1999-10-04 22:25:02 phaller 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 | class Win32DllBase : public virtual Win32ImageBase
 | 
|---|
| 32 | {
 | 
|---|
| 33 | public:
 | 
|---|
| 34 |                   Win32DllBase(HINSTANCE hInstance, WIN32DLLENTRY DllEntryPoint);
 | 
|---|
| 35 | virtual          ~Win32DllBase();
 | 
|---|
| 36 | 
 | 
|---|
| 37 |         ULONG     AddRef()           { return ++referenced; };
 | 
|---|
| 38 |         //ASSUMPTION: called by FreeLibrary only
 | 
|---|
| 39 | virtual ULONG     Release();
 | 
|---|
| 40 |         char     *getName()          { return szModule; };
 | 
|---|
| 41 |         void      setNoEntryCalls()  { fSkipEntryCalls = TRUE; };
 | 
|---|
| 42 | 
 | 
|---|
| 43 |         Win32DllBase *getNext()  { return next; };
 | 
|---|
| 44 | static  Win32DllBase *getFirst();
 | 
|---|
| 45 | 
 | 
|---|
| 46 | //Send DLL_THREAD_ATTACH message to all dlls for a new thread
 | 
|---|
| 47 | static  void      attachThreadToAllDlls();
 | 
|---|
| 48 | 
 | 
|---|
| 49 | //Send DLL_THREAD_DETACH message to all dlls for thread that's about to die
 | 
|---|
| 50 | static  void      detachThreadFromAllDlls();
 | 
|---|
| 51 | 
 | 
|---|
| 52 | //Setup TLS structure for all dlls for a new thread
 | 
|---|
| 53 | static  void      tlsAttachThreadToAllDlls();
 | 
|---|
| 54 | 
 | 
|---|
| 55 | //Destroy TLS structure for all dlls for a thread that's about to die
 | 
|---|
| 56 | static  void      tlsDetachThreadFromAllDlls();
 | 
|---|
| 57 | 
 | 
|---|
| 58 | virtual ULONG     getApi(char *name)  = 0;
 | 
|---|
| 59 | virtual ULONG     getApi(int ordinal) = 0;
 | 
|---|
| 60 | 
 | 
|---|
| 61 |         BOOL      attachProcess();
 | 
|---|
| 62 |         BOOL      detachProcess();
 | 
|---|
| 63 |         BOOL      attachThread();
 | 
|---|
| 64 |         BOOL      detachThread();
 | 
|---|
| 65 | 
 | 
|---|
| 66 | // enable / disable thread attach/detach calls
 | 
|---|
| 67 |         void      setThreadLibraryCalls(BOOL fEnable);
 | 
|---|
| 68 | 
 | 
|---|
| 69 | static  void      deleteAll();
 | 
|---|
| 70 | 
 | 
|---|
| 71 | static  BOOL      isSystemDll(char *szFileName);
 | 
|---|
| 72 | 
 | 
|---|
| 73 | virtual BOOL      isLxDll() = 0;
 | 
|---|
| 74 | virtual BOOL      isDll();
 | 
|---|
| 75 | 
 | 
|---|
| 76 | static  Win32DllBase *findModule(char *dllname);
 | 
|---|
| 77 | static  Win32DllBase *findModule(HINSTANCE hinstance);
 | 
|---|
| 78 | static  Win32DllBase *findModule(WIN32DLLENTRY DllEntryPoint);
 | 
|---|
| 79 | 
 | 
|---|
| 80 | protected:
 | 
|---|
| 81 |         BOOL          fSkipEntryCalls, fUnloaded, fAttachedToProcess;
 | 
|---|
| 82 | 
 | 
|---|
| 83 |         WIN32DLLENTRY dllEntryPoint;
 | 
|---|
| 84 | 
 | 
|---|
| 85 |         ULONG         referenced;
 | 
|---|
| 86 | 
 | 
|---|
| 87 | private:
 | 
|---|
| 88 | static  Win32DllBase *head;
 | 
|---|
| 89 |         Win32DllBase *next;
 | 
|---|
| 90 | };
 | 
|---|
| 91 | 
 | 
|---|
| 92 | #endif
 | 
|---|