Bump for 3.6-28
[LibreOffice.git] / xmerge / source / activesync / XMergeSync.cpp
blob4d346ee690e9ce919bd589be3985b1ab363a4244
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 #include "stdafx.h"
5 #include "XMergeFilter.h"
6 #include "XMergeFactory.h"
9 CXMergeSyncModule _Module;
12 //////////////////////////////////////////////////////////////////////
13 // DLL Functions
14 //////////////////////////////////////////////////////////////////////
15 BOOL WINAPI DllMain(HANDLE hInst, ULONG ulReason, LPVOID lpReserved)
17 switch (ulReason)
19 case DLL_PROCESS_ATTACH:
20 _Module.m_hInst = reinterpret_cast<HINSTANCE>(hInst);
21 break;
23 case DLL_PROCESS_DETACH:
24 _Module.m_hInst = NULL;
25 break;
27 case DLL_THREAD_ATTACH:
28 break;
30 case DLL_THREAD_DETACH:
31 break;
34 return TRUE;
38 STDAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID *ppv)
40 // Create the factory object
41 CXMergeFactory *pFactory = new CXMergeFactory();
42 if (pFactory == NULL)
44 *ppv = NULL;
45 return E_OUTOFMEMORY;
48 HRESULT hr = pFactory->QueryInterface(riid, ppv);
49 pFactory->Release();
51 return hr;
55 STDAPI DllCanUnloadNow()
57 if (_Module.GetLockCount() == 0)
58 return S_OK;
60 return S_FALSE;
64 // Utility function to close open keys during registration
65 static _signalRegError(long lRet, HKEY hKey, HKEY hDataKey)
67 if (hKey)
68 ::RegCloseKey(hKey);
71 if (hDataKey)
72 ::RegCloseKey(hDataKey);
74 return HRESULT_FROM_WIN32(lRet);
78 STDAPI DllRegisterServer()
80 HKEY hKey = NULL;
81 HKEY hDataKey = NULL;
83 long lRet = 0;
84 TCHAR sTemp[_MAX_PATH + 1] = "\0";
88 * Following calls create the HKEY_CLASSES_ROOT\CLSID entry for the Writer export filter.
90 * Note that import are export are relative to the WinCE device, so files are
91 * exported to the desktop format.
94 // Get a handle to the CLSID key
95 lRet = ::RegOpenKeyEx(HKEY_CLASSES_ROOT, _T("CLSID"), 0, KEY_ALL_ACCESS, &hKey);
96 if (lRet != ERROR_SUCCESS)
97 return _signalRegError(lRet, hKey, hDataKey);
99 // Create the CLSID key for the XMergeFilter
100 lRet = ::RegCreateKeyEx(hKey, CXMergeFilter::m_pszPSWExportCLSID, 0, _T(""), 0, KEY_ALL_ACCESS, NULL, &hKey, NULL);
101 if (lRet != ERROR_SUCCESS)
102 return _signalRegError(lRet, hKey, hDataKey);
104 lRet = ::RegSetValueEx(hKey, _T(""), 0, REG_SZ, (LPBYTE)CXMergeFilter::m_pszPSWExportShortDesc,
105 (::_tcslen(CXMergeFilter::m_pszPSWExportShortDesc) * sizeof(TCHAR) + (1 * sizeof(TCHAR))));
106 if (lRet != ERROR_SUCCESS)
107 return _signalRegError(lRet, hKey, hDataKey);
110 // Create the DefaultIcon key. For the moment, use one of the Async supplied ones
111 lRet = ::RegCreateKeyEx(hKey, _T("DefaultIcon"), 0, _T(""), 0, KEY_ALL_ACCESS, NULL, &hDataKey, NULL);
112 if (lRet != ERROR_SUCCESS)
113 return _signalRegError(lRet, hKey, hDataKey);
115 lRet = ::RegSetValueEx(hDataKey, NULL, 0, REG_SZ, (LPBYTE)_T("C:\\Program Files\\Microsoft ActiveSync\\pwdcnv.dll,0"),
116 (::_tcslen(_T("C:\\Program Files\\Microsoft ActiveSync\\pwdcnv.dll,0"))
117 * sizeof(TCHAR) + (1 * sizeof(TCHAR))));
118 if (lRet != ERROR_SUCCESS)
119 return _signalRegError(lRet, hKey, hDataKey);
120 ::RegCloseKey(hDataKey); hDataKey = NULL;
122 // Create the InprocServer32 key
123 lRet = ::RegCreateKeyEx(hKey, _T("InProcServer32"), 0, _T(""), 0, KEY_ALL_ACCESS, NULL, &hDataKey, NULL);
124 if (lRet != ERROR_SUCCESS)
125 return _signalRegError(lRet, hKey, hDataKey);
127 lRet = ::RegSetValueEx(hDataKey, _T("ThreadingModel"), 0, REG_SZ, (LPBYTE)_T("Apartment"), 10);
128 if (lRet != ERROR_SUCCESS)
129 return _signalRegError(lRet, hKey, hDataKey);
131 // Create the key for the DLL file. First find the filename of the dll
132 if (!::GetModuleFileName((HMODULE)_Module.m_hInst, sTemp, (_MAX_PATH + 1)))
134 lRet = ::GetLastError();
135 if (lRet != ERROR_SUCCESS)
136 return _signalRegError(lRet, hKey, hDataKey);
140 lRet = ::RegSetValueEx(hDataKey, NULL, 0, REG_SZ, (LPBYTE)sTemp,
141 (::_tcslen(sTemp) * sizeof(TCHAR) + (1 * sizeof(TCHAR))));
142 if (lRet != ERROR_SUCCESS)
143 return _signalRegError(lRet, hKey, hDataKey);
144 ::RegCloseKey(hDataKey); hDataKey = NULL;
147 // Setup the PegasusFilter key values
148 lRet = ::RegCreateKeyEx(hKey, _T("PegasusFilter"), 0, _T(""), 0, KEY_ALL_ACCESS, NULL, &hDataKey, NULL);
149 if (lRet != ERROR_SUCCESS)
150 return _signalRegError(lRet, hKey, hDataKey);
152 lRet = ::RegSetValueEx(hDataKey, _T("Description"), 0, REG_SZ, (LPBYTE)CXMergeFilter::m_pszPSWExportDesc,
153 (::_tcslen(CXMergeFilter::m_pszPSWExportDesc) * sizeof(TCHAR) + (1 * sizeof(TCHAR))));
154 if (lRet != ERROR_SUCCESS)
155 return _signalRegError(lRet, hKey, hDataKey);
158 lRet = ::RegSetValueEx(hDataKey, _T("Export"), 0, REG_SZ, (LPBYTE)_T(""), (1 * sizeof(TCHAR)));
159 if (lRet != ERROR_SUCCESS)
160 return _signalRegError(lRet, hKey, hDataKey);
163 lRet = ::RegSetValueEx(hDataKey, _T("NewExtension"), 0, REG_SZ, (LPBYTE)CXMergeFilter::m_pszPSWExportExt,
164 (::_tcslen(CXMergeFilter::m_pszPSWExportExt) * sizeof(TCHAR) + (1 * sizeof(TCHAR))));
165 if (lRet != ERROR_SUCCESS)
166 return _signalRegError(lRet, hKey, hDataKey);
169 ::RegCloseKey(hKey); hKey = NULL;
170 ::RegCloseKey(hDataKey); hDataKey = NULL;
176 * Following calls create the entries for the filter in
177 * HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows CE Services\Filters
180 lRet = ::RegOpenKeyEx(HKEY_LOCAL_MACHINE, _T("SOFTWARE\\Microsoft\\Windows CE Services\\Filters"),
181 0, KEY_ALL_ACCESS, &hKey);
182 if (lRet != ERROR_SUCCESS)
183 return _signalRegError(lRet, hKey, hDataKey);
185 _snprintf(sTemp, _MAX_PATH + 1, "%c%s\\InstalledFilters\0", '.', CXMergeFilter::m_pszPSWImportExt);
186 lRet = ::RegCreateKeyEx(hKey, _T(sTemp),
187 0, _T(""), 0, KEY_ALL_ACCESS, NULL, &hDataKey, NULL);
188 if (lRet != ERROR_SUCCESS)
189 return _signalRegError(lRet, hKey, hDataKey);
191 lRet = ::RegSetValueEx(hDataKey, CXMergeFilter::m_pszPSWExportCLSID, 0, REG_SZ, (LPBYTE)_T(""), (1 * sizeof(TCHAR)));
192 if (lRet != ERROR_SUCCESS)
193 return _signalRegError(lRet, hKey, hDataKey);
195 ::RegCloseKey(hKey); hKey = NULL;
196 ::RegCloseKey(hDataKey); hDataKey = NULL;
201 * Following calls create the HKEY_CLASSES_ROOT\CLSID entry for the Writer import filter.
203 * Note that import are export are relative to the WinCE device, so files are
204 * exported to the desktop format.
206 // Get a handle to the CLSID key
207 lRet = ::RegOpenKeyEx(HKEY_CLASSES_ROOT, _T("CLSID"), 0, KEY_ALL_ACCESS, &hKey);
208 if (lRet != ERROR_SUCCESS)
209 return _signalRegError(lRet, hKey, hDataKey);
211 // Create the CLSID key for the XMergeFilter
212 lRet = ::RegCreateKeyEx(hKey, CXMergeFilter::m_pszPSWImportCLSID, 0, _T(""), 0, KEY_ALL_ACCESS, NULL, &hKey, NULL);
213 if (lRet != ERROR_SUCCESS)
214 return _signalRegError(lRet, hKey, hDataKey);
216 lRet = ::RegSetValueEx(hKey, _T(""), 0, REG_SZ, (LPBYTE)CXMergeFilter::m_pszPSWImportShortDesc,
217 (::_tcslen(CXMergeFilter::m_pszPSWImportShortDesc) * sizeof(TCHAR) + (1 * sizeof(TCHAR))));
218 if (lRet != ERROR_SUCCESS)
219 return _signalRegError(lRet, hKey, hDataKey);
222 // Create the DefaultIcon key. For the moment, use one of the Async supplied ones
223 lRet = ::RegCreateKeyEx(hKey, _T("DefaultIcon"), 0, _T(""), 0, KEY_ALL_ACCESS, NULL, &hDataKey, NULL);
224 if (lRet != ERROR_SUCCESS)
225 return _signalRegError(lRet, hKey, hDataKey);
227 lRet = ::RegSetValueEx(hDataKey, NULL, 0, REG_SZ, (LPBYTE)_T("C:\\Program Files\\Microsoft ActiveSync\\pwdcnv.dll,0"),
228 (::_tcslen(_T("C:\\Program Files\\Microsoft ActiveSync\\pwdcnv.dll,0"))
229 * sizeof(TCHAR) + (1 * sizeof(TCHAR))));
230 if (lRet != ERROR_SUCCESS)
231 return _signalRegError(lRet, hKey, hDataKey);
232 ::RegCloseKey(hDataKey); hDataKey = NULL;
235 // Create the InprocServer32 key
236 lRet = ::RegCreateKeyEx(hKey, _T("InProcServer32"), 0, _T(""), 0, KEY_ALL_ACCESS, NULL, &hDataKey, NULL);
237 if (lRet != ERROR_SUCCESS)
238 return _signalRegError(lRet, hKey, hDataKey);
240 lRet = ::RegSetValueEx(hDataKey, _T("ThreadingModel"), 0, REG_SZ, (LPBYTE)_T("Apartment"), 10);
241 if (lRet != ERROR_SUCCESS)
242 return _signalRegError(lRet, hKey, hDataKey);
245 // Create the key for the DLL file. First find the filename of the dll
246 if (!::GetModuleFileName((HMODULE)_Module.m_hInst, sTemp, (_MAX_PATH + 1)))
248 lRet = ::GetLastError();
249 if (lRet != ERROR_SUCCESS)
250 return _signalRegError(lRet, hKey, hDataKey);
254 lRet = ::RegSetValueEx(hDataKey, NULL, 0, REG_SZ, (LPBYTE)sTemp,
255 (::_tcslen(sTemp) * sizeof(TCHAR) + (1 * sizeof(TCHAR))));
256 if (lRet != ERROR_SUCCESS)
257 return _signalRegError(lRet, hKey, hDataKey);
258 ::RegCloseKey(hDataKey); hDataKey = NULL;
261 // Setup the PegasusFilter key values
262 lRet = ::RegCreateKeyEx(hKey, _T("PegasusFilter"), 0, _T(""), 0, KEY_ALL_ACCESS, NULL, &hDataKey, NULL);
263 if (lRet != ERROR_SUCCESS)
264 return _signalRegError(lRet, hKey, hDataKey);
266 lRet = ::RegSetValueEx(hDataKey, _T("Description"), 0, REG_SZ, (LPBYTE)CXMergeFilter::m_pszPSWImportDesc,
267 (::_tcslen(CXMergeFilter::m_pszPSWImportDesc) * sizeof(TCHAR) + (1 * sizeof(TCHAR))));
268 if (lRet != ERROR_SUCCESS)
269 return _signalRegError(lRet, hKey, hDataKey);
272 lRet = ::RegSetValueEx(hDataKey, _T("Import"), 0, REG_SZ, (LPBYTE)_T(""), (1 * sizeof(TCHAR)));
273 if (lRet != ERROR_SUCCESS)
274 return _signalRegError(lRet, hKey, hDataKey);
277 lRet = ::RegSetValueEx(hDataKey, _T("NewExtension"), 0, REG_SZ, (LPBYTE)CXMergeFilter::m_pszPSWImportExt,
278 (::_tcslen(CXMergeFilter::m_pszPSWImportExt) * sizeof(TCHAR) + (1 * sizeof(TCHAR))));
279 if (lRet != ERROR_SUCCESS)
280 return _signalRegError(lRet, hKey, hDataKey);
283 ::RegCloseKey(hKey); hKey = NULL;
284 ::RegCloseKey(hDataKey); hDataKey = NULL;
288 * Following calls create the entries for the filter in
289 * HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows CE Services\Filters
291 lRet = ::RegOpenKeyEx(HKEY_LOCAL_MACHINE, _T("SOFTWARE\\Microsoft\\Windows CE Services\\Filters"),
292 0, KEY_ALL_ACCESS, &hKey);
293 if (lRet != ERROR_SUCCESS)
294 return _signalRegError(lRet, hKey, hDataKey);
296 // Add in defaults for import and export
297 _snprintf(sTemp, _MAX_PATH +1, "%c%s\0", '.', CXMergeFilter::m_pszPSWExportExt);
298 lRet = ::RegCreateKeyEx(hKey, _T(sTemp), 0, _T(""), 0, KEY_ALL_ACCESS, NULL, &hDataKey, NULL);
299 if (lRet != ERROR_SUCCESS)
300 return _signalRegError(lRet, hKey, hDataKey);
302 lRet = ::RegSetValueEx(hDataKey, _T("DefaultImport"), 0, REG_SZ,
303 (LPBYTE)CXMergeFilter::m_pszPSWImportCLSID,
304 (::_tcslen(CXMergeFilter::m_pszPSWImportDesc) * sizeof(TCHAR) + (1 * sizeof(TCHAR))));
305 if (lRet != ERROR_SUCCESS)
306 return _signalRegError(lRet, hKey, hDataKey);
309 lRet = ::RegSetValueEx(hDataKey, _T("DefaultExport"), 0, REG_SZ, (LPBYTE)_T("Binary Copy"),
310 (::_tcslen(_T("Binary Copy")) * sizeof(TCHAR) + (1 * sizeof(TCHAR))));
311 if (lRet != ERROR_SUCCESS)
312 return _signalRegError(lRet, hKey, hDataKey);
314 ::RegCloseKey(hDataKey);
316 // Update registered filters
317 _snprintf(sTemp, _MAX_PATH + 1, "%c%s\\InstalledFilters\0", '.', CXMergeFilter::m_pszPSWExportExt);
318 lRet = ::RegCreateKeyEx(hKey, _T(sTemp),
319 0, _T(""), 0, KEY_ALL_ACCESS, NULL, &hDataKey, NULL);
320 if (lRet != ERROR_SUCCESS)
321 return _signalRegError(lRet, hKey, hDataKey);
324 lRet = ::RegSetValueEx(hDataKey, CXMergeFilter::m_pszPSWImportCLSID, 0, REG_SZ, (LPBYTE)_T(""), (1 * sizeof(TCHAR)));
325 if (lRet != ERROR_SUCCESS)
326 return _signalRegError(lRet, hKey, hDataKey);
328 ::RegCloseKey(hKey); hKey = NULL;
329 ::RegCloseKey(hDataKey); hDataKey = NULL;
334 * Following calls create the HKEY_CLASSES_ROOT\CLSID entry for the Calc export filter.
336 * Note that import are export are relative to the WinCE device, so files are
337 * exported to the desktop format.
340 // Get a handle to the CLSID key
341 lRet = ::RegOpenKeyEx(HKEY_CLASSES_ROOT, _T("CLSID"), 0, KEY_ALL_ACCESS, &hKey);
342 if (lRet != ERROR_SUCCESS)
343 return _signalRegError(lRet, hKey, hDataKey);
345 // Create the CLSID key for the XMerge Filter
346 lRet = ::RegCreateKeyEx(hKey, CXMergeFilter::m_pszPXLExportCLSID, 0, _T(""),
347 0, KEY_ALL_ACCESS, NULL, &hKey, NULL);
348 if (lRet != ERROR_SUCCESS)
349 return _signalRegError(lRet, hKey, hDataKey);
351 lRet = ::RegSetValueEx(hKey, _T(""), 0, REG_SZ, (LPBYTE)CXMergeFilter::m_pszPXLExportShortDesc,
352 (::_tcslen(CXMergeFilter::m_pszPXLExportShortDesc) * sizeof(TCHAR) + (1 * sizeof(TCHAR))));
353 if (lRet != ERROR_SUCCESS)
354 return _signalRegError(lRet, hKey, hDataKey);
357 // Create the DefaultIcon key. For the moment, use one of the Async supplied ones
358 lRet = ::RegCreateKeyEx(hKey, _T("DefaultIcon"), 0, _T(""), 0, KEY_ALL_ACCESS, NULL, &hDataKey, NULL);
359 if (lRet != ERROR_SUCCESS)
360 return _signalRegError(lRet, hKey, hDataKey);
362 lRet = ::RegSetValueEx(hDataKey, NULL, 0, REG_SZ, (LPBYTE)_T("C:\\Program Files\\Microsoft ActiveSync\\pwdcnv.dll,0"),
363 (::_tcslen(_T("C:\\Program Files\\Microsoft ActiveSync\\pwdcnv.dll,0"))
364 * sizeof(TCHAR) + (1 * sizeof(TCHAR))));
365 if (lRet != ERROR_SUCCESS)
366 return _signalRegError(lRet, hKey, hDataKey);
367 ::RegCloseKey(hDataKey); hDataKey = NULL;
370 // Create the InprocServer32 key
371 lRet = ::RegCreateKeyEx(hKey, _T("InProcServer32"), 0, _T(""), 0, KEY_ALL_ACCESS, NULL, &hDataKey, NULL);
372 if (lRet != ERROR_SUCCESS)
373 return _signalRegError(lRet, hKey, hDataKey);
375 lRet = ::RegSetValueEx(hDataKey, _T("ThreadingModel"), 0, REG_SZ, (LPBYTE)_T("Apartment"), 10);
376 if (lRet != ERROR_SUCCESS)
377 return _signalRegError(lRet, hKey, hDataKey);
380 // Create the key for the DLL file. First find the filename of the dll
381 if (!::GetModuleFileName((HMODULE)_Module.m_hInst, sTemp, (_MAX_PATH + 1)))
383 lRet = ::GetLastError();
384 if (lRet != ERROR_SUCCESS)
385 return _signalRegError(lRet, hKey, hDataKey);
389 lRet = ::RegSetValueEx(hDataKey, NULL, 0, REG_SZ, (LPBYTE)sTemp,
390 (::_tcslen(sTemp) * sizeof(TCHAR) + (1 * sizeof(TCHAR))));
391 if (lRet != ERROR_SUCCESS)
392 return _signalRegError(lRet, hKey, hDataKey);
393 ::RegCloseKey(hDataKey); hDataKey = NULL;
396 // Setup the PegasusFilter key values
397 lRet = ::RegCreateKeyEx(hKey, _T("PegasusFilter"), 0, _T(""), 0, KEY_ALL_ACCESS, NULL, &hDataKey, NULL);
398 if (lRet != ERROR_SUCCESS)
399 return _signalRegError(lRet, hKey, hDataKey);
401 lRet = ::RegSetValueEx(hDataKey, _T("Description"), 0, REG_SZ, (LPBYTE)CXMergeFilter::m_pszPXLExportDesc,
402 (::_tcslen(CXMergeFilter::m_pszPXLExportDesc) * sizeof(TCHAR) + (1 * sizeof(TCHAR))));
403 if (lRet != ERROR_SUCCESS)
404 return _signalRegError(lRet, hKey, hDataKey);
407 lRet = ::RegSetValueEx(hDataKey, _T("Export"), 0, REG_SZ, (LPBYTE)_T(""), (1 * sizeof(TCHAR)));
408 if (lRet != ERROR_SUCCESS)
409 return _signalRegError(lRet, hKey, hDataKey);
412 lRet = ::RegSetValueEx(hDataKey, _T("NewExtension"), 0, REG_SZ, (LPBYTE)CXMergeFilter::m_pszPXLExportExt,
413 (::_tcslen(CXMergeFilter::m_pszPXLExportExt) * sizeof(TCHAR) + (1 * sizeof(TCHAR))));
414 if (lRet != ERROR_SUCCESS)
415 return _signalRegError(lRet, hKey, hDataKey);
418 ::RegCloseKey(hKey); hKey = NULL;
419 ::RegCloseKey(hDataKey); hDataKey = NULL;
425 * Following calls create the entries for the filter in
426 * HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows CE Services\Filters
429 lRet = ::RegOpenKeyEx(HKEY_LOCAL_MACHINE, _T("SOFTWARE\\Microsoft\\Windows CE Services\\Filters"),
430 0, KEY_ALL_ACCESS, &hKey);
431 if (lRet != ERROR_SUCCESS)
432 return _signalRegError(lRet, hKey, hDataKey);
434 _snprintf(sTemp, _MAX_PATH + 1, "%c%s\\InstalledFilters\0", '.', CXMergeFilter::m_pszPXLImportExt);
435 lRet = ::RegCreateKeyEx(hKey, _T(sTemp),
436 0, _T(""), 0, KEY_ALL_ACCESS, NULL, &hDataKey, NULL);
437 if (lRet != ERROR_SUCCESS)
438 return _signalRegError(lRet, hKey, hDataKey);
440 lRet = ::RegSetValueEx(hDataKey, CXMergeFilter::m_pszPXLExportCLSID, 0, REG_SZ, (LPBYTE)_T(""), (1 * sizeof(TCHAR)));
441 if (lRet != ERROR_SUCCESS)
442 return _signalRegError(lRet, hKey, hDataKey);
444 ::RegCloseKey(hKey); hKey = NULL;
445 ::RegCloseKey(hDataKey); hDataKey = NULL;
450 * Following calls create the HKEY_CLASSES_ROOT\CLSID entry for the Calc import filter.
452 * Note that import are export are relative to the WinCE device, so files are
453 * exported to the desktop format.
455 // Get a handle to the CLSID key
456 lRet = ::RegOpenKeyEx(HKEY_CLASSES_ROOT, _T("CLSID"), 0, KEY_ALL_ACCESS, &hKey);
457 if (lRet != ERROR_SUCCESS)
458 return _signalRegError(lRet, hKey, hDataKey);
461 // Create the CLSID key for the XMergeFilter
462 lRet = ::RegCreateKeyEx(hKey, CXMergeFilter::m_pszPXLImportCLSID, 0, _T(""), 0, KEY_ALL_ACCESS, NULL, &hKey, NULL);
463 if (lRet != ERROR_SUCCESS)
464 return _signalRegError(lRet, hKey, hDataKey);
466 lRet = ::RegSetValueEx(hKey, _T(""), 0, REG_SZ, (LPBYTE)CXMergeFilter::m_pszPXLImportShortDesc,
467 (::_tcslen(CXMergeFilter::m_pszPXLImportShortDesc) * sizeof(TCHAR) + (1 * sizeof(TCHAR))));
468 if (lRet != ERROR_SUCCESS)
469 return _signalRegError(lRet, hKey, hDataKey);
471 // Create the DefaultIcon key. For the moment, use one of the Async supplied ones
472 lRet = ::RegCreateKeyEx(hKey, _T("DefaultIcon"), 0, _T(""), 0, KEY_ALL_ACCESS, NULL, &hDataKey, NULL);
473 if (lRet != ERROR_SUCCESS)
474 return _signalRegError(lRet, hKey, hDataKey);
476 lRet = ::RegSetValueEx(hDataKey, NULL, 0, REG_SZ, (LPBYTE)_T("C:\\Program Files\\Microsoft ActiveSync\\pwdcnv.dll,0"),
477 (::_tcslen(_T("C:\\Program Files\\Microsoft ActiveSync\\pwdcnv.dll,0"))
478 * sizeof(TCHAR) + (1 * sizeof(TCHAR))));
479 if (lRet != ERROR_SUCCESS)
480 return _signalRegError(lRet, hKey, hDataKey);
481 ::RegCloseKey(hDataKey); hDataKey = NULL;
484 // Create the InprocServer32 key
485 lRet = ::RegCreateKeyEx(hKey, _T("InProcServer32"), 0, _T(""), 0, KEY_ALL_ACCESS, NULL, &hDataKey, NULL);
486 if (lRet != ERROR_SUCCESS)
487 return _signalRegError(lRet, hKey, hDataKey);
489 lRet = ::RegSetValueEx(hDataKey, _T("ThreadingModel"), 0, REG_SZ, (LPBYTE)_T("Apartment"), 10);
490 if (lRet != ERROR_SUCCESS)
491 return _signalRegError(lRet, hKey, hDataKey);
494 // Create the key for the DLL file. First find the filename of the dll
495 if (!::GetModuleFileName((HMODULE)_Module.m_hInst, sTemp, (_MAX_PATH + 1)))
497 lRet = ::GetLastError();
498 if (lRet != ERROR_SUCCESS)
499 return _signalRegError(lRet, hKey, hDataKey);
503 lRet = ::RegSetValueEx(hDataKey, NULL, 0, REG_SZ, (LPBYTE)sTemp,
504 (::_tcslen(sTemp) * sizeof(TCHAR) + (1 * sizeof(TCHAR))));
505 if (lRet != ERROR_SUCCESS)
506 return _signalRegError(lRet, hKey, hDataKey);
507 ::RegCloseKey(hDataKey); hDataKey = NULL;
510 // Setup the PegasusFilter key values
511 lRet = ::RegCreateKeyEx(hKey, _T("PegasusFilter"), 0, _T(""), 0, KEY_ALL_ACCESS, NULL, &hDataKey, NULL);
512 if (lRet != ERROR_SUCCESS)
513 return _signalRegError(lRet, hKey, hDataKey);
515 lRet = ::RegSetValueEx(hDataKey, _T("Description"), 0, REG_SZ, (LPBYTE)CXMergeFilter::m_pszPXLImportDesc,
516 (::_tcslen(CXMergeFilter::m_pszPXLImportDesc) * sizeof(TCHAR) + (1 * sizeof(TCHAR))));
517 if (lRet != ERROR_SUCCESS)
518 return _signalRegError(lRet, hKey, hDataKey);
521 lRet = ::RegSetValueEx(hDataKey, _T("Import"), 0, REG_SZ, (LPBYTE)_T(""), (1 * sizeof(TCHAR)));
522 if (lRet != ERROR_SUCCESS)
523 return _signalRegError(lRet, hKey, hDataKey);
526 lRet = ::RegSetValueEx(hDataKey, _T("NewExtension"), 0, REG_SZ, (LPBYTE)CXMergeFilter::m_pszPXLImportExt,
527 (::_tcslen(CXMergeFilter::m_pszPXLImportExt) * sizeof(TCHAR) + (1 * sizeof(TCHAR))));
528 if (lRet != ERROR_SUCCESS)
529 return _signalRegError(lRet, hKey, hDataKey);
532 ::RegCloseKey(hKey); hKey = NULL;
533 ::RegCloseKey(hDataKey); hDataKey = NULL;
538 * Following calls create the entries for the filter in
539 * HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows CE Services\Filters
541 lRet = ::RegOpenKeyEx(HKEY_LOCAL_MACHINE, _T("SOFTWARE\\Microsoft\\Windows CE Services\\Filters"),
542 0, KEY_ALL_ACCESS, &hKey);
543 if (lRet != ERROR_SUCCESS)
544 return _signalRegError(lRet, hKey, hDataKey);
546 // Add in defaults for import and export
547 _snprintf(sTemp, _MAX_PATH +1, "%c%s\0", '.', CXMergeFilter::m_pszPXLExportExt);
548 lRet = ::RegCreateKeyEx(hKey, _T(sTemp), 0, _T(""), 0, KEY_ALL_ACCESS, NULL, &hDataKey, NULL);
549 if (lRet != ERROR_SUCCESS)
550 return _signalRegError(lRet, hKey, hDataKey);
552 lRet = ::RegSetValueEx(hDataKey, _T("DefaultImport"), 0, REG_SZ,
553 (LPBYTE)CXMergeFilter::m_pszPXLImportCLSID,
554 (::_tcslen(CXMergeFilter::m_pszPSWImportDesc) * sizeof(TCHAR) + (1 * sizeof(TCHAR))));
555 if (lRet != ERROR_SUCCESS)
556 return _signalRegError(lRet, hKey, hDataKey);
559 lRet = ::RegSetValueEx(hDataKey, _T("DefaultExport"), 0, REG_SZ, (LPBYTE)_T("Binary Copy"),
560 (::_tcslen(_T("Binary Copy")) * sizeof(TCHAR) + (1 * sizeof(TCHAR))));
561 if (lRet != ERROR_SUCCESS)
562 return _signalRegError(lRet, hKey, hDataKey);
564 ::RegCloseKey(hDataKey);
566 // Update registered filters
569 _snprintf(sTemp, _MAX_PATH + 1, "%c%s\\InstalledFilters\0", '.', CXMergeFilter::m_pszPXLExportExt);
570 lRet = ::RegCreateKeyEx(hKey, _T(sTemp),
571 0, _T(""), 0, KEY_ALL_ACCESS, NULL, &hDataKey, NULL);
572 if (lRet != ERROR_SUCCESS)
573 return _signalRegError(lRet, hKey, hDataKey);
575 lRet = ::RegSetValueEx(hDataKey, CXMergeFilter::m_pszPXLImportCLSID, 0, REG_SZ, (LPBYTE)_T(""), (1 * sizeof(TCHAR)));
576 if (lRet != ERROR_SUCCESS)
577 return _signalRegError(lRet, hKey, hDataKey);
579 ::RegCloseKey(hKey); hKey = NULL;
580 ::RegCloseKey(hDataKey); hDataKey = NULL;
584 return HRESULT_FROM_WIN32(lRet);
588 STDAPI DllUnregisterServer()
590 long lRet = 0;
591 HKEY hKey = NULL;
592 HKEY hDataKey = NULL;
594 TCHAR szClassName[_MAX_PATH] = "\0";
595 TCHAR szKeyName[_MAX_PATH] = "\0";
596 DWORD dwClassName = _MAX_PATH;
597 DWORD dwKeyName = _MAX_PATH;
600 * Remove HKEY_CLASS_ROOT\CLSID\{XXX} entry for the export and import filters
602 * Windows 95/98/Me allow one step deletion of a key and all subkeys.
603 * Windows NT/2000/XP do not so the subkeys must be deleted individually.
605 lRet = ::RegOpenKeyEx(HKEY_CLASSES_ROOT, _T("CLSID"), 0, KEY_ALL_ACCESS, &hKey);
606 if (lRet != ERROR_SUCCESS)
607 return _signalRegError(lRet, hKey, hDataKey);
610 // First up, the Writer export filter
611 lRet = ::RegOpenKeyEx(hKey, CXMergeFilter::m_pszPSWExportCLSID, 0, KEY_ALL_ACCESS, &hDataKey);
612 if (lRet != ERROR_SUCCESS)
613 return _signalRegError(lRet, hKey, hDataKey);
616 while ((lRet = ::RegEnumKeyEx(hDataKey, 0, szKeyName, &dwKeyName, 0, szClassName, &dwClassName, NULL))
617 != ERROR_NO_MORE_ITEMS)
619 lRet = ::RegDeleteKey(hDataKey, szKeyName);
621 ::lstrcpy(szKeyName, "\0");
622 ::lstrcpy(szClassName, "\0");
624 dwClassName = _MAX_PATH;
625 dwKeyName = _MAX_PATH;
628 ::RegCloseKey(hDataKey); hDataKey = NULL;
630 lRet = ::RegDeleteKey(hKey, CXMergeFilter::m_pszPSWExportCLSID);
631 if (lRet != ERROR_SUCCESS && lRet != ERROR_FILE_NOT_FOUND)
632 return _signalRegError(lRet, hKey, hDataKey);
636 // Next, the Writer import filter
637 lRet = ::RegOpenKeyEx(hKey, CXMergeFilter::m_pszPSWImportCLSID, 0, KEY_ALL_ACCESS, &hDataKey);
638 if (lRet != ERROR_SUCCESS)
639 return _signalRegError(lRet, hKey, hDataKey);
642 while ((lRet = ::RegEnumKeyEx(hDataKey, 0, szKeyName, &dwKeyName, 0, szClassName, &dwClassName, NULL))
643 != ERROR_NO_MORE_ITEMS)
645 lRet = ::RegDeleteKey(hDataKey, szKeyName);
647 ::lstrcpy(szKeyName, "\0");
648 ::lstrcpy(szClassName, "\0");
650 dwClassName = _MAX_PATH;
651 dwKeyName = _MAX_PATH;
654 ::RegCloseKey(hDataKey); hDataKey = NULL;
656 lRet = ::RegDeleteKey(hKey, CXMergeFilter::m_pszPSWImportCLSID);
657 if (lRet != ERROR_SUCCESS && lRet != ERROR_FILE_NOT_FOUND)
658 return _signalRegError(lRet, hKey, hDataKey);
661 // Next up, the Calc export filter
662 lRet = ::RegOpenKeyEx(hKey, CXMergeFilter::m_pszPXLExportCLSID, 0, KEY_ALL_ACCESS, &hDataKey);
663 if (lRet != ERROR_SUCCESS)
664 return _signalRegError(lRet, hKey, hDataKey);
667 while ((lRet = ::RegEnumKeyEx(hDataKey, 0, szKeyName, &dwKeyName, 0, szClassName, &dwClassName, NULL))
668 != ERROR_NO_MORE_ITEMS)
670 lRet = ::RegDeleteKey(hDataKey, szKeyName);
672 ::lstrcpy(szKeyName, "\0");
673 ::lstrcpy(szClassName, "\0");
675 dwClassName = _MAX_PATH;
676 dwKeyName = _MAX_PATH;
679 ::RegCloseKey(hDataKey); hDataKey = NULL;
681 lRet = ::RegDeleteKey(hKey, CXMergeFilter::m_pszPXLExportCLSID);
682 if (lRet != ERROR_SUCCESS && lRet != ERROR_FILE_NOT_FOUND)
683 return _signalRegError(lRet, hKey, hDataKey);
686 // Next, the Calc import filter
687 lRet = ::RegOpenKeyEx(hKey, CXMergeFilter::m_pszPXLImportCLSID, 0, KEY_ALL_ACCESS, &hDataKey);
688 if (lRet != ERROR_SUCCESS)
689 return _signalRegError(lRet, hKey, hDataKey);
692 while ((lRet = ::RegEnumKeyEx(hDataKey, 0, szKeyName, &dwKeyName, 0, szClassName, &dwClassName, NULL))
693 != ERROR_NO_MORE_ITEMS)
695 lRet = ::RegDeleteKey(hDataKey, szKeyName);
697 ::lstrcpy(szKeyName, "\0");
698 ::lstrcpy(szClassName, "\0");
700 dwClassName = _MAX_PATH;
701 dwKeyName = _MAX_PATH;
704 ::RegCloseKey(hDataKey); hDataKey = NULL;
706 lRet = ::RegDeleteKey(hKey, CXMergeFilter::m_pszPXLImportCLSID);
707 if (lRet != ERROR_SUCCESS && lRet != ERROR_FILE_NOT_FOUND)
708 return _signalRegError(lRet, hKey, hDataKey);
710 ::RegCloseKey(hKey); hKey = NULL;
715 * Remove the HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows CE Services\Filters
717 lRet = ::RegOpenKeyEx(HKEY_LOCAL_MACHINE, _T("SOFTWARE\\Microsoft\\Windows CE Services\\Filters"),
718 0, KEY_ALL_ACCESS, &hKey);
719 if (lRet != ERROR_SUCCESS)
720 return _signalRegError(lRet, hKey, hDataKey);
723 // Remove the Writer export filter from the Writer import file extension subkey.
724 _snprintf(szKeyName, _MAX_PATH, ".%s\\InstalledFilters", CXMergeFilter::m_pszPSWImportExt);
725 lRet = ::RegOpenKeyEx(hKey, _T(szKeyName), 0, KEY_ALL_ACCESS, &hDataKey);
726 if (lRet != ERROR_SUCCESS)
727 return _signalRegError(lRet, hKey, hDataKey);
729 lRet = ::RegDeleteValue(hDataKey, CXMergeFilter::m_pszPSWExportCLSID);
730 if (lRet != ERROR_SUCCESS)
731 return _signalRegError(lRet, hKey, hDataKey);
733 ::lstrcpyn(szKeyName, "\0", _MAX_PATH);
734 ::RegCloseKey(hDataKey); hDataKey = NULL;
737 // Remove the Writer import filter from the Writer export file extension subkey.
738 _snprintf(szKeyName, _MAX_PATH, ".%s\\InstalledFilters", CXMergeFilter::m_pszPSWExportExt);
739 lRet = ::RegOpenKeyEx(hKey, _T(szKeyName), 0, KEY_ALL_ACCESS, &hDataKey);
740 if (lRet != ERROR_SUCCESS)
741 return _signalRegError(lRet, hKey, hDataKey);
743 lRet = ::RegDeleteValue(hDataKey, CXMergeFilter::m_pszPSWImportCLSID);
744 if (lRet != ERROR_SUCCESS)
745 return _signalRegError(lRet, hKey, hDataKey);
747 ::lstrcpyn(szKeyName, "\0", _MAX_PATH);
748 ::RegCloseKey(hDataKey); hDataKey = NULL;
751 // Make Binary Copy the default for Writer export file extension subkey DefaultImport
752 _snprintf(szKeyName, _MAX_PATH, ".%s\0", CXMergeFilter::m_pszPSWExportExt);
753 lRet = ::RegOpenKeyEx(hKey, _T(szKeyName), 0, KEY_ALL_ACCESS, &hDataKey);
754 if (lRet != ERROR_SUCCESS)
755 return _signalRegError(lRet, hKey, hDataKey);
757 lRet = ::RegSetValueEx(hDataKey, _T("DefaultImport"), 0, REG_SZ, (LPBYTE)_T("Binary Copy"),
758 (::_tcslen(_T("Binary Copy")) * sizeof(TCHAR) + (1 * sizeof(TCHAR))));
759 if (lRet != ERROR_SUCCESS)
760 return _signalRegError(lRet, hKey, hDataKey);
762 ::lstrcpyn(szKeyName, "\0", _MAX_PATH);
763 ::RegCloseKey(hDataKey); hDataKey = NULL;
766 // Remove the Calc export filter from the Calc import file extension subkey.
767 _snprintf(szKeyName, _MAX_PATH, ".%s\\InstalledFilters", CXMergeFilter::m_pszPXLImportExt);
768 lRet = ::RegOpenKeyEx(hKey, _T(szKeyName), 0, KEY_ALL_ACCESS, &hDataKey);
769 if (lRet != ERROR_SUCCESS)
770 return _signalRegError(lRet, hKey, hDataKey);
772 lRet = ::RegDeleteValue(hDataKey, CXMergeFilter::m_pszPXLExportCLSID);
773 if (lRet != ERROR_SUCCESS)
774 return _signalRegError(lRet, hKey, hDataKey);
776 ::lstrcpyn(szKeyName, "\0", _MAX_PATH);
777 ::RegCloseKey(hDataKey); hDataKey = NULL;
779 // Remove the Calc import filter from the Calc export file extension subkey.
780 _snprintf(szKeyName, _MAX_PATH, ".%s\\InstalledFilters", CXMergeFilter::m_pszPXLExportExt);
781 lRet = ::RegOpenKeyEx(hKey, _T(szKeyName), 0, KEY_ALL_ACCESS, &hDataKey);
782 if (lRet != ERROR_SUCCESS)
783 return _signalRegError(lRet, hKey, hDataKey);
785 lRet = ::RegDeleteValue(hDataKey, CXMergeFilter::m_pszPXLImportCLSID);
786 if (lRet != ERROR_SUCCESS)
787 return _signalRegError(lRet, hKey, hDataKey);
789 ::lstrcpyn(szKeyName, "\0", _MAX_PATH);
790 ::RegCloseKey(hDataKey); hDataKey = NULL;
793 // Make Binary Copy the default for Calc export file extension subkey DefaultImport
794 _snprintf(szKeyName, _MAX_PATH, ".%s\0", CXMergeFilter::m_pszPXLExportExt);
795 lRet = ::RegOpenKeyEx(hKey, _T(szKeyName), 0, KEY_ALL_ACCESS, &hDataKey);
796 if (lRet != ERROR_SUCCESS)
797 return _signalRegError(lRet, hKey, hDataKey);
799 lRet = ::RegSetValueEx(hDataKey, _T("DefaultImport"), 0, REG_SZ, (LPBYTE)_T("Binary Copy"),
800 (::_tcslen(_T("Binary Copy")) * sizeof(TCHAR) + (1 * sizeof(TCHAR))));
801 if (lRet != ERROR_SUCCESS)
802 return _signalRegError(lRet, hKey, hDataKey);
804 ::lstrcpyn(szKeyName, "\0", _MAX_PATH);
805 ::RegCloseKey(hDataKey); hDataKey = NULL;
809 ::RegCloseKey(hKey); hKey = NULL;
811 return HRESULT_FROM_WIN32(lRet);
815 //////////////////////////////////////////////////////////////////////
816 // CXMergeSyncModule methods
817 //////////////////////////////////////////////////////////////////////
818 CXMergeSyncModule::CXMergeSyncModule () : m_lLocks(0), m_lObjs(0)
822 CXMergeSyncModule::~CXMergeSyncModule ()
826 long CXMergeSyncModule::LockServer(BOOL fLock)
828 if(fLock)
829 return ::InterlockedIncrement(&m_lLocks);
830 else
831 return ::InterlockedDecrement(&m_lLocks);
834 long CXMergeSyncModule::GetLockCount() const
836 return m_lLocks + m_lObjs;
839 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */