1 // DLLExports2.cpp
2 
3 #include "StdAfx.h"
4 
5 #include "../../Common/MyWindows.h"
6 
7 #include "../../Common/MyInitGuid.h"
8 
9 #if defined(_7ZIP_LARGE_PAGES)
10 #include "../../../C/Alloc.h"
11 #endif
12 
13 #include "../../Common/ComTry.h"
14 
15 #include "../../Windows/NtCheck.h"
16 #include "../../Windows/PropVariant.h"
17 
18 #include "../ICoder.h"
19 #include "../IPassword.h"
20 
21 #include "../Common/CreateCoder.h"
22 
23 #include "IArchive.h"
24 
25 
26 #ifdef _WIN32
27 
28 #if defined(_UNICODE) && !defined(_WIN64) && !defined(UNDER_CE)
29 #define NT_CHECK_FAIL_ACTION return FALSE;
30 #endif
31 
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 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 = 0;
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(_7ZIP_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 #ifdef EXTERNAL_CODECS
129 
130 CExternalCodecs g_ExternalCodecs;
131 
132 STDAPI SetCodecs(ICompressCodecsInfo *compressCodecsInfo);
SetCodecs(ICompressCodecsInfo * compressCodecsInfo)133 STDAPI SetCodecs(ICompressCodecsInfo *compressCodecsInfo)
134 {
135   COM_TRY_BEGIN
136 
137   // OutputDebugStringA(compressCodecsInfo ? "SetCodecs" : "SetCodecs NULL");
138   if (compressCodecsInfo)
139   {
140     g_ExternalCodecs.GetCodecs = compressCodecsInfo;
141     return g_ExternalCodecs.Load();
142   }
143   g_ExternalCodecs.ClearAndRelease();
144   return S_OK;
145 
146   COM_TRY_END
147 }
148 
149 #else
150 
151 STDAPI SetCodecs(ICompressCodecsInfo *);
SetCodecs(ICompressCodecsInfo *)152 STDAPI SetCodecs(ICompressCodecsInfo *)
153 {
154   return S_OK;
155 }
156 
157 #endif
158