1 // DLLExports2.cpp
2
3 #include "StdAfx.h"
4
5 #include "../../Common/MyWindows.h"
6 #include "../../Common/MyInitGuid.h"
7
8 #if defined(Z7_LARGE_PAGES)
9 #include "../../../C/Alloc.h"
10 #endif
11
12 #include "../../Common/ComTry.h"
13
14 #include "../../Windows/NtCheck.h"
15 #include "../../Windows/PropVariant.h"
16
17 #include "../ICoder.h"
18 #include "../IPassword.h"
19
20 #include "../Common/CreateCoder.h"
21
22 #include "IArchive.h"
23
24
25 #ifdef _WIN32
26
27 #if defined(_UNICODE) && !defined(_WIN64) && !defined(UNDER_CE)
28 #define NT_CHECK_FAIL_ACTION return FALSE;
29 #endif
30
31 static
32 HINSTANCE g_hInstance;
33
34 extern "C"
35 BOOL WINAPI DllMain(
36 #ifdef UNDER_CE
37 HANDLE
38 #else
39 HINSTANCE
40 #endif
41 hInstance, DWORD dwReason, LPVOID /*lpReserved*/);
42
43 extern "C"
DllMain(HANDLE hInstance,DWORD dwReason,LPVOID)44 BOOL WINAPI DllMain(
45 #ifdef UNDER_CE
46 HANDLE
47 #else
48 HINSTANCE
49 #endif
50 hInstance, DWORD dwReason, LPVOID /*lpReserved*/)
51 {
52 if (dwReason == DLL_PROCESS_ATTACH)
53 {
54 // OutputDebugStringA("7z.dll DLL_PROCESS_ATTACH");
55 g_hInstance = (HINSTANCE)hInstance;
56 NT_CHECK
57 }
58 /*
59 if (dwReason == DLL_PROCESS_DETACH)
60 {
61 OutputDebugStringA("7z.dll DLL_PROCESS_DETACH");
62 }
63 */
64 return TRUE;
65 }
66
67 #else // _WIN32
68
69 #include "../../Common/StringConvert.h"
70 // #include <stdio.h>
71
72 // STDAPI LibStartup();
73 static __attribute__((constructor)) void Init_ForceToUTF8();
Init_ForceToUTF8()74 static __attribute__((constructor)) void Init_ForceToUTF8()
75 {
76 g_ForceToUTF8 = IsNativeUTF8();
77 // printf("\nDLLExports2.cpp::Init_ForceToUTF8 =%d\n", g_ForceToUTF8 ? 1 : 0);
78 }
79
80 #endif // _WIN32
81
82
83 Z7_DEFINE_GUID(CLSID_CArchiveHandler,
84 k_7zip_GUID_Data1,
85 k_7zip_GUID_Data2,
86 k_7zip_GUID_Data3_Common,
87 0x10, 0x00, 0x00, 0x01, 0x10, 0x00, 0x00, 0x00);
88
89 STDAPI CreateCoder(const GUID *clsid, const GUID *iid, void **outObject);
90 STDAPI CreateHasher(const GUID *clsid, IHasher **hasher);
91 STDAPI CreateArchiver(const GUID *clsid, const GUID *iid, void **outObject);
92
93 STDAPI CreateObject(const GUID *clsid, const GUID *iid, void **outObject);
CreateObject(const GUID * clsid,const GUID * iid,void ** outObject)94 STDAPI CreateObject(const GUID *clsid, const GUID *iid, void **outObject)
95 {
96 // COM_TRY_BEGIN
97 *outObject = NULL;
98 if (*iid == IID_ICompressCoder ||
99 *iid == IID_ICompressCoder2 ||
100 *iid == IID_ICompressFilter)
101 return CreateCoder(clsid, iid, outObject);
102 if (*iid == IID_IHasher)
103 return CreateHasher(clsid, (IHasher **)outObject);
104 return CreateArchiver(clsid, iid, outObject);
105 // COM_TRY_END
106 }
107
108 STDAPI SetLargePageMode();
SetLargePageMode()109 STDAPI SetLargePageMode()
110 {
111 #if defined(Z7_LARGE_PAGES)
112 #ifdef _WIN32
113 SetLargePageSize();
114 #endif
115 #endif
116 return S_OK;
117 }
118
119 extern bool g_CaseSensitive;
120
121 STDAPI SetCaseSensitive(Int32 caseSensitive);
SetCaseSensitive(Int32 caseSensitive)122 STDAPI SetCaseSensitive(Int32 caseSensitive)
123 {
124 g_CaseSensitive = (caseSensitive != 0);
125 return S_OK;
126 }
127
128 /*
129 UInt32 g_ClientVersion;
130 STDAPI SetClientVersion(UInt32 version);
131 STDAPI SetClientVersion(UInt32 version)
132 {
133 g_ClientVersion = version;
134 return S_OK;
135 }
136 */
137
138 /*
139 STDAPI SetProperty(Int32 id, const PROPVARIANT *value);
140 STDAPI SetProperty(Int32 id, const PROPVARIANT *value)
141 {
142 return S_OK;
143 }
144 */
145
146 #ifdef Z7_EXTERNAL_CODECS
147
148 CExternalCodecs g_ExternalCodecs;
149
150 STDAPI SetCodecs(ICompressCodecsInfo *compressCodecsInfo);
SetCodecs(ICompressCodecsInfo * compressCodecsInfo)151 STDAPI SetCodecs(ICompressCodecsInfo *compressCodecsInfo)
152 {
153 COM_TRY_BEGIN
154
155 // OutputDebugStringA(compressCodecsInfo ? "SetCodecs" : "SetCodecs NULL");
156 if (compressCodecsInfo)
157 {
158 g_ExternalCodecs.GetCodecs = compressCodecsInfo;
159 return g_ExternalCodecs.Load();
160 }
161 g_ExternalCodecs.ClearAndRelease();
162 return S_OK;
163
164 COM_TRY_END
165 }
166
167 #else
168
169 STDAPI SetCodecs(ICompressCodecsInfo *);
SetCodecs(ICompressCodecsInfo *)170 STDAPI SetCodecs(ICompressCodecsInfo *)
171 {
172 return S_OK;
173 }
174
175 #endif
176