1 | /* $Id: windll.h,v 1.3 1999-07-07 08:11:09 sandervl Exp $ */
|
---|
2 |
|
---|
3 | /*
|
---|
4 | *
|
---|
5 | * Project Odin Software License can be found in LICENSE.TXT
|
---|
6 | *
|
---|
7 | */
|
---|
8 | /*
|
---|
9 | * Win32 PE Dll class
|
---|
10 | *
|
---|
11 | * Copyright 1998 Sander van Leeuwen (sandervl@xs4all.nl)
|
---|
12 | *
|
---|
13 | */
|
---|
14 | #ifndef __WINDLL_H__
|
---|
15 | #define __WINDLL_H__
|
---|
16 |
|
---|
17 | #include "winimage.h"
|
---|
18 |
|
---|
19 | #ifndef CCHMAXPATH
|
---|
20 | #define CCHMAXPATH 260
|
---|
21 | #endif
|
---|
22 | #ifndef HINSTANCE
|
---|
23 | #define HINSTANCE ULONG
|
---|
24 | #endif
|
---|
25 |
|
---|
26 | #define DLL_PROCESS_ATTACH 1
|
---|
27 | #define DLL_THREAD_ATTACH 2
|
---|
28 | #define DLL_THREAD_DETACH 3
|
---|
29 | #define DLL_PROCESS_DETACH 0
|
---|
30 |
|
---|
31 | #define DONT_RESOLVE_DLL_REFERENCES 0x00000001
|
---|
32 | #define LOAD_LIBRARY_AS_DATAFILE 0x00000002
|
---|
33 | #define LOAD_WITH_ALTERED_SEARCH_PATH 0x00000008
|
---|
34 |
|
---|
35 | typedef ULONG (* WIN32API WIN32DLLENTRY)(ULONG hInstance, ULONG reason, ULONG reserved);
|
---|
36 |
|
---|
37 | class Win32Dll : public Win32Image
|
---|
38 | {
|
---|
39 | public:
|
---|
40 | Win32Dll(HINSTANCE hinstance, int NameTableId, int Win32TableId, WIN32DLLENTRY DllEntryPoint);
|
---|
41 | Win32Dll(char *szDllName);
|
---|
42 | ~Win32Dll();
|
---|
43 |
|
---|
44 | void OS2DllInit(HINSTANCE hinstance, int NameTableId, int Win32TableId,
|
---|
45 | WIN32DLLENTRY DllEntryPoint);
|
---|
46 |
|
---|
47 | BOOL init();
|
---|
48 |
|
---|
49 | ULONG AddRef() { return ++referenced; };
|
---|
50 | //ASSUMPTION: called by FreeLibrary only
|
---|
51 | ULONG Release();
|
---|
52 | char *getName() { return szModule; };
|
---|
53 | void setNoEntryCalls() { fSkipEntryCalls = TRUE; };
|
---|
54 |
|
---|
55 | Win32Dll *getNext() { return next; };
|
---|
56 | static Win32Dll *getFirst();
|
---|
57 |
|
---|
58 | //Send DLL_THREAD_ATTACH message to all dlls for a new thread
|
---|
59 | static void attachThreadToAllDlls();
|
---|
60 |
|
---|
61 | //Send DLL_THREAD_DETACH message to all dlls for thread that's about to die
|
---|
62 | static void detachThreadFromAllDlls();
|
---|
63 |
|
---|
64 | //Setup TLS structure for all dlls for a new thread
|
---|
65 | static void tlsAttachThreadToAllDlls();
|
---|
66 |
|
---|
67 | //Destroy TLS structure for all dlls for a thread that's about to die
|
---|
68 | static void tlsDetachThreadFromAllDlls();
|
---|
69 |
|
---|
70 | ULONG getApi(char *name);
|
---|
71 | ULONG getApi(int ordinal);
|
---|
72 | BOOL attachProcess();
|
---|
73 | BOOL detachProcess();
|
---|
74 | BOOL attachThread();
|
---|
75 | BOOL detachThread();
|
---|
76 |
|
---|
77 | static void deleteAll();
|
---|
78 |
|
---|
79 | static BOOL isSystemDll(char *szFileName);
|
---|
80 |
|
---|
81 | static Win32Dll *findModule(char *dllname);
|
---|
82 | static Win32Dll *findModule(HINSTANCE hinstance);
|
---|
83 | static Win32Dll *findModule(WIN32DLLENTRY DllEntryPoint);
|
---|
84 |
|
---|
85 | protected:
|
---|
86 | BOOL fSystemDll, fSkipEntryCalls, fUnloaded;
|
---|
87 |
|
---|
88 | WIN32DLLENTRY dllEntryPoint;
|
---|
89 | private:
|
---|
90 | ULONG referenced;
|
---|
91 | char szModule[CCHMAXPATH];
|
---|
92 |
|
---|
93 | char *StripPath(char *path);
|
---|
94 |
|
---|
95 |
|
---|
96 | static Win32Dll *head;
|
---|
97 | Win32Dll *next;
|
---|
98 | };
|
---|
99 |
|
---|
100 | #endif
|
---|