diff options
author | Igor Pavlov <87184205+ip7z@users.noreply.github.com> | 2021-12-27 00:00:00 +0000 |
---|---|---|
committer | Igor Pavlov <87184205+ip7z@users.noreply.github.com> | 2022-03-18 15:35:13 +0500 |
commit | f19f813537c7aea1c20749c914e756b54a9c3cf5 (patch) | |
tree | 816ba62ca7c0fa19f2eb46d9e9d6f7dd7c3a744d /CPP/Windows/DLL.h | |
parent | 98e06a519b63b81986abe76d28887f6984a7732b (diff) | |
download | 7zip-21.07.tar.gz 7zip-21.07.tar.bz2 7zip-21.07.zip |
'21.07'21.07
Diffstat (limited to 'CPP/Windows/DLL.h')
-rw-r--r-- | CPP/Windows/DLL.h | 84 |
1 files changed, 84 insertions, 0 deletions
diff --git a/CPP/Windows/DLL.h b/CPP/Windows/DLL.h new file mode 100644 index 0000000..0c093ee --- /dev/null +++ b/CPP/Windows/DLL.h | |||
@@ -0,0 +1,84 @@ | |||
1 | // Windows/DLL.h | ||
2 | |||
3 | #ifndef __WINDOWS_DLL_H | ||
4 | #define __WINDOWS_DLL_H | ||
5 | |||
6 | #include "../Common/MyString.h" | ||
7 | |||
8 | namespace NWindows { | ||
9 | namespace NDLL { | ||
10 | |||
11 | #ifdef _WIN32 | ||
12 | |||
13 | #ifdef UNDER_CE | ||
14 | #define My_GetProcAddress(module, procName) (void *)::GetProcAddressA(module, procName) | ||
15 | #else | ||
16 | #define My_GetProcAddress(module, procName) (void *)::GetProcAddress(module, procName) | ||
17 | #endif | ||
18 | |||
19 | /* Win32: Don't call CLibrary::Free() and FreeLibrary() from another | ||
20 | FreeLibrary() code: detaching code in DLL entry-point or in | ||
21 | destructors of global objects in DLL module. */ | ||
22 | |||
23 | class CLibrary | ||
24 | { | ||
25 | HMODULE _module; | ||
26 | |||
27 | // CLASS_NO_COPY(CLibrary); | ||
28 | public: | ||
29 | CLibrary(): _module(NULL) {}; | ||
30 | ~CLibrary() { Free(); } | ||
31 | |||
32 | operator HMODULE() const { return _module; } | ||
33 | HMODULE* operator&() { return &_module; } | ||
34 | bool IsLoaded() const { return (_module != NULL); } | ||
35 | |||
36 | void Attach(HMODULE m) | ||
37 | { | ||
38 | Free(); | ||
39 | _module = m; | ||
40 | } | ||
41 | HMODULE Detach() | ||
42 | { | ||
43 | HMODULE m = _module; | ||
44 | _module = NULL; | ||
45 | return m; | ||
46 | } | ||
47 | |||
48 | bool Free() throw(); | ||
49 | bool LoadEx(CFSTR path, DWORD flags = LOAD_LIBRARY_AS_DATAFILE) throw(); | ||
50 | bool Load(CFSTR path) throw(); | ||
51 | // FARPROC | ||
52 | void *GetProc(LPCSTR procName) const { return My_GetProcAddress(_module, procName); } | ||
53 | }; | ||
54 | |||
55 | #else | ||
56 | |||
57 | typedef void * HMODULE; | ||
58 | // typedef int (*FARPROC)(); | ||
59 | // typedef void *FARPROC; | ||
60 | |||
61 | class CLibrary | ||
62 | { | ||
63 | HMODULE _module; | ||
64 | |||
65 | // CLASS_NO_COPY(CLibrary); | ||
66 | public: | ||
67 | CLibrary(): _module(NULL) {}; | ||
68 | ~CLibrary() { Free(); } | ||
69 | |||
70 | bool Free() throw(); | ||
71 | bool Load(CFSTR path) throw(); | ||
72 | // FARPROC | ||
73 | void *GetProc(LPCSTR procName) const; // { return My_GetProcAddress(_module, procName); } | ||
74 | }; | ||
75 | |||
76 | #endif | ||
77 | |||
78 | bool MyGetModuleFileName(FString &path); | ||
79 | |||
80 | FString GetModuleDirPrefix(); | ||
81 | |||
82 | }} | ||
83 | |||
84 | #endif | ||