-
Notifications
You must be signed in to change notification settings - Fork 141
Expand file tree
/
Copy pathMapWinGIS.cpp
More file actions
256 lines (206 loc) · 8.49 KB
/
MapWinGIS.cpp
File metadata and controls
256 lines (206 loc) · 8.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
// MapWinGIS.cpp : Implementation of CMapWinGISApp and DLL registration.
#include "stdafx.h"
#include <initguid.h>
#include "MapWinGIS_i.c"
#include "ShapefileColorScheme.h"
#include "ShapefileColorBreak.h"
#include "cpl_conv.h"
#include "cpl_string.h"
#include "map.h"
#include "Functions.h"
#include "PointClass.h"
#ifdef _DEBUG
#include "gdal.h"
#define new DEBUG_NEW
#endif
#include "MercatorProjection.h"
#include "PrefetchManager.h"
#include "TileCacheManager.h"
class CMapWinGISModule :
public ATL::CAtlMfcModule
{
public:
DECLARE_LIBID(LIBID_MapWinGIS);
DECLARE_REGISTRY_APPID_RESOURCEID(IDR_MAPWINGIS, "{8308CC9E-4AEF-4D31-9081-86CD61B9E641}");
};
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
const GUID CDECL BASED_CODE _tlid = { 0xc368d713, 0xcc5f, 0x40ed, { 0x9f, 0x53, 0xf8, 0x4f, 0xe1, 0x97, 0xb9, 0x6a } };
const WORD _wVerMajor = 5;
const WORD _wVerMinor = 4;
CMapWinGISApp NEAR theApp;
CMapWinGISModule _AtlModule; // this one is from ATL7 (used by all ATL co-classes)
CComModule _Module; // this one is from ATL3 (used for ShapefileColorScheme and ShapefileColorBreak)
GlobalClassFactory m_factory; // make sure that this one is initialized after the _Module above
// ******************************************************
// CMapWinGISApp::InitInstance - DLL initialization
// ******************************************************
BOOL CMapWinGISApp::InitInstance()
{
// let's generate floating point exceptions
#ifndef RELEASE_MODE
//_clearfp();
//_controlfp(0, EM_ZERODIVIDE);
#endif
Debug::Init();
//Neio modified 2009, following http_://www.mapwindow.org/phorum/read.php?7,12162 by gischai, for multi-language support
//std::locale::global(std::locale(""));
//19-Oct-09 Rob Cairns: (See Bug 1446) - I hate doing this if it prevents our Chinese friends opening Chinese character shapefiles and data.
//However, there are just too many bugs associated with this change. See Bug 1446 for more information. Changing back to classic.
std::locale::global(std::locale("C"));
// http_://stackoverflow.com/questions/7659127/createex-causes-unhandled-exception-the-activation-context-being-deactivated-is
//AfxSetAmbientActCtx(FALSE);
// UTF8 string are expected by default; the enviroment variable shoud be set to restore older behavior
// see more details here: http_://trac.osgeo.org/gdal/wiki/ConfigOptions
m_globalSettings.SetGdalUtf8(false);
GdalHelper::SetDefaultConfigPaths();
parser::InitializeFunctions();
// initialize all static variables, to keep our memory leaking report clean from them
#ifdef _DEBUG
gMemLeakDetect.stopped = true;
GDALAllRegister();
gMemLeakDetect.stopped = false;
#endif
//CMapView::GdiplusStartup(); // moved back to CMapView constructor
return COleControlModule::InitInstance() && InitATL();
}
// *****************************************************
// CMapWinGISApp::ExitInstance - DLL termination
// *****************************************************
int CMapWinGISApp::ExitInstance()
{
CPLErrorReset();
MercatorProjection::ReleaseGeoProjection();
#ifndef RELEASE_MODE
CComBSTR bstr;
// make sure m_utils is still extant
if (m_utils)
{
m_utils->get_ComUsageReport(VARIANT_TRUE, &bstr);
}
USES_CONVERSION;
CString s = OLE2A(bstr);
Debug::WriteLine(s);
#endif
if (m_utils)
{
m_utils->Release();
}
TileCacheManager::CloseAll();
PrefetchManagerFactory::Clear();
parser::ReleaseFunctions();
//CMapView::GdiplusShutdown(); // moved back to CMapView destructor
_Module.Term();
return COleControlModule::ExitInstance();
}
// **************************************************************
// DllRegisterServer - Adds entries to the system registry
// **************************************************************
STDAPI DllRegisterServer(void)
{
_AtlModule.UpdateRegistryAppId(TRUE);
HRESULT hRes2 = _AtlModule.RegisterServer(TRUE);
if (hRes2 != S_OK)
return hRes2;
AFX_MANAGE_STATE(_afxModuleAddrThis);
if (!AfxOleRegisterTypeLib(AfxGetInstanceHandle(), _tlid))
return ResultFromScode(SELFREG_E_TYPELIB);
if (!COleObjectFactoryEx::UpdateRegistryAll(TRUE))
return ResultFromScode(SELFREG_E_CLASS);
return _Module.RegisterServer(TRUE);
return NOERROR;
}
// **************************************************************
// GetModuleInstance
// **************************************************************
HINSTANCE GetModuleInstance()
{
HINSTANCE instance = _Module.GetModuleInstance();
return instance;
}
// **************************************************************
// DllUnregisterServer - Removes entries from the system registry
// **************************************************************
STDAPI DllUnregisterServer(void)
{
_AtlModule.UpdateRegistryAppId(FALSE);
HRESULT hRes2 = _AtlModule.UnregisterServer(TRUE);
if (hRes2 != S_OK)
return hRes2;
AFX_MANAGE_STATE(_afxModuleAddrThis);
if (!AfxOleUnregisterTypeLib(_tlid, _wVerMajor, _wVerMinor))
return ResultFromScode(SELFREG_E_TYPELIB);
if (!COleObjectFactoryEx::UpdateRegistryAll(FALSE))
return ResultFromScode(SELFREG_E_CLASS);
_Module.UnregisterServer(TRUE); //TRUE indicates that typelib is unreg'd
return NOERROR;
}
#if !defined(_WIN32_WCE) && !defined(_AMD64_) && !defined(_IA64_)
#pragma comment(linker, "/EXPORT:DllCanUnloadNow=_DllCanUnloadNow@0,PRIVATE")
#pragma comment(linker, "/EXPORT:DllGetClassObject=_DllGetClassObject@12,PRIVATE")
#pragma comment(linker, "/EXPORT:DllRegisterServer=_DllRegisterServer@0,PRIVATE")
#pragma comment(linker, "/EXPORT:DllUnregisterServer=_DllUnregisterServer@0,PRIVATE")
#else
#if defined(_X86_) || defined(_SHX_)
#pragma comment(linker, "/EXPORT:DllCanUnloadNow=_DllCanUnloadNow,PRIVATE")
#pragma comment(linker, "/EXPORT:DllGetClassObject=_DllGetClassObject,PRIVATE")
#pragma comment(linker, "/EXPORT:DllRegisterServer=_DllRegisterServer,PRIVATE")
#pragma comment(linker, "/EXPORT:DllUnregisterServer=_DllUnregisterServer,PRIVATE")
#else
#pragma comment(linker, "/EXPORT:DllCanUnloadNow,PRIVATE")
#pragma comment(linker, "/EXPORT:DllGetClassObject,PRIVATE")
#pragma comment(linker, "/EXPORT:DllRegisterServer,PRIVATE")
#pragma comment(linker, "/EXPORT:DllUnregisterServer,PRIVATE")
#endif // (_X86_)||(_SHX_)
#endif // !_WIN32_WCE && !_AMD64_ && !_IA64_
// **************************************************************
// DllCanUnloadNow()
// **************************************************************
STDAPI DllCanUnloadNow(void)
{
AFX_MANAGE_STATE(AfxGetStaticModuleState());
if (_AtlModule.GetLockCount() > 0)
return S_FALSE;
return (AfxDllCanUnloadNow() == S_OK && _Module.GetLockCount() == 0) ? S_OK : S_FALSE;
}
// ******************************************************************
// Returns a class factory to create an object of the requested type
// ******************************************************************
STDAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID* ppv)
{
#ifdef _DEBUG
bool state = gMemLeakDetect.stopped;
gMemLeakDetect.stopped = true;
#endif
AFX_MANAGE_STATE(AfxGetStaticModuleState());
HRESULT hres;
if (S_OK == _AtlModule.GetClassObject(rclsid, riid, ppv))
hres = S_OK;
else if (AfxDllGetClassObject(rclsid, riid, ppv) == S_OK)
hres = S_OK;
else
hres = _Module.GetClassObject(rclsid, riid, ppv);
#ifdef _DEBUG
gMemLeakDetect.stopped = state;
#endif
return hres;
}
// *****************************************************************
// Object map
// *****************************************************************
// Provides support for the registration, initialization, and creation of instances of ATL COM classes
// According to MSDN this macro is obsolete. OBJECT_ENTRY_AUTO should be used instead
BEGIN_OBJECT_MAP(ObjectMap)
#ifdef OLD_API
OBJECT_ENTRY(CLSID_ShapefileColorScheme, CShapefileColorScheme)
OBJECT_ENTRY(CLSID_ShapefileColorBreak, CShapefileColorBreak)
#endif
END_OBJECT_MAP()
// *****************************************************************
// InitATL
// *****************************************************************
BOOL CMapWinGISApp::InitATL()
{
_Module.Init(ObjectMap, AfxGetInstanceHandle());
return TRUE;
}