aboutsummaryrefslogtreecommitdiff
path: root/CPP/Windows/DLL.h
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--CPP/Windows/DLL.h49
1 files changed, 34 insertions, 15 deletions
diff --git a/CPP/Windows/DLL.h b/CPP/Windows/DLL.h
index 0c093ee..19a82b3 100644
--- a/CPP/Windows/DLL.h
+++ b/CPP/Windows/DLL.h
@@ -1,20 +1,29 @@
1// Windows/DLL.h 1// Windows/DLL.h
2 2
3#ifndef __WINDOWS_DLL_H 3#ifndef ZIP7_INC_WINDOWS_DLL_H
4#define __WINDOWS_DLL_H 4#define ZIP7_INC_WINDOWS_DLL_H
5 5
6#include "../Common/MyString.h" 6#include "../Common/MyString.h"
7 7
8#ifndef _WIN32
9typedef void * HMODULE;
10// typedef int (*FARPROC)();
11// typedef void *FARPROC;
12void *GetProcAddress(HMODULE module, LPCSTR procName);
13#endif
14
8namespace NWindows { 15namespace NWindows {
9namespace NDLL { 16namespace NDLL {
10 17
11#ifdef _WIN32 18#ifdef _WIN32
12 19
20/*
13#ifdef UNDER_CE 21#ifdef UNDER_CE
14#define My_GetProcAddress(module, procName) (void *)::GetProcAddressA(module, procName) 22#define My_GetProcAddress(module, procName) (void *)::GetProcAddressA(module, procName)
15#else 23#else
16#define My_GetProcAddress(module, procName) (void *)::GetProcAddress(module, procName) 24#define My_GetProcAddress(module, procName) (void *)::GetProcAddress(module, procName)
17#endif 25#endif
26*/
18 27
19/* Win32: Don't call CLibrary::Free() and FreeLibrary() from another 28/* Win32: Don't call CLibrary::Free() and FreeLibrary() from another
20 FreeLibrary() code: detaching code in DLL entry-point or in 29 FreeLibrary() code: detaching code in DLL entry-point or in
@@ -24,13 +33,25 @@ class CLibrary
24{ 33{
25 HMODULE _module; 34 HMODULE _module;
26 35
27 // CLASS_NO_COPY(CLibrary); 36 // Z7_CLASS_NO_COPY(CLibrary);
37 // copy constructor is required here
28public: 38public:
29 CLibrary(): _module(NULL) {}; 39 CLibrary(): _module(NULL) {}
30 ~CLibrary() { Free(); } 40 ~CLibrary() { Free(); }
31 41
32 operator HMODULE() const { return _module; } 42 CLibrary(const CLibrary &c): _module(NULL)
33 HMODULE* operator&() { return &_module; } 43 {
44 if (c._module)
45 {
46 // we need non const to reference from original item
47 // c._module = NULL;
48 throw 20230102;
49 }
50 }
51
52 HMODULE Get_HMODULE() const { return _module; }
53 // operator HMODULE() const { return _module; }
54 // HMODULE* operator&() { return &_module; }
34 bool IsLoaded() const { return (_module != NULL); } 55 bool IsLoaded() const { return (_module != NULL); }
35 56
36 void Attach(HMODULE m) 57 void Attach(HMODULE m)
@@ -40,7 +61,7 @@ public:
40 } 61 }
41 HMODULE Detach() 62 HMODULE Detach()
42 { 63 {
43 HMODULE m = _module; 64 const HMODULE m = _module;
44 _module = NULL; 65 _module = NULL;
45 return m; 66 return m;
46 } 67 }
@@ -49,28 +70,26 @@ public:
49 bool LoadEx(CFSTR path, DWORD flags = LOAD_LIBRARY_AS_DATAFILE) throw(); 70 bool LoadEx(CFSTR path, DWORD flags = LOAD_LIBRARY_AS_DATAFILE) throw();
50 bool Load(CFSTR path) throw(); 71 bool Load(CFSTR path) throw();
51 // FARPROC 72 // FARPROC
52 void *GetProc(LPCSTR procName) const { return My_GetProcAddress(_module, procName); } 73 // void *GetProc(LPCSTR procName) const { return My_GetProcAddress(_module, procName); }
53}; 74};
54 75
55#else 76#else
56 77
57typedef void * HMODULE;
58// typedef int (*FARPROC)();
59// typedef void *FARPROC;
60
61class CLibrary 78class CLibrary
62{ 79{
63 HMODULE _module; 80 HMODULE _module;
64 81
65 // CLASS_NO_COPY(CLibrary); 82 // Z7_CLASS_NO_COPY(CLibrary);
66public: 83public:
67 CLibrary(): _module(NULL) {}; 84 CLibrary(): _module(NULL) {}
68 ~CLibrary() { Free(); } 85 ~CLibrary() { Free(); }
69 86
87 HMODULE Get_HMODULE() const { return _module; }
88
70 bool Free() throw(); 89 bool Free() throw();
71 bool Load(CFSTR path) throw(); 90 bool Load(CFSTR path) throw();
72 // FARPROC 91 // FARPROC
73 void *GetProc(LPCSTR procName) const; // { return My_GetProcAddress(_module, procName); } 92 // void *GetProc(LPCSTR procName) const; // { return My_GetProcAddress(_module, procName); }
74}; 93};
75 94
76#endif 95#endif