update dev300-m58
[ooovba.git] / xmerge / source / activesync / XMergeSync.cpp
blobebbaacd7714609259cbb756b18e0eddd22255372
2 #include "stdafx.h"
4 #include "XMergeFilter.h"
5 #include "XMergeFactory.h"
8 CXMergeSyncModule _Module;
11 //////////////////////////////////////////////////////////////////////
12 // DLL Functions
13 //////////////////////////////////////////////////////////////////////
14 BOOL WINAPI DllMain(HANDLE hInst, ULONG ulReason, LPVOID lpReserved)
16 switch (ulReason)
18 case DLL_PROCESS_ATTACH:
19 _Module.m_hInst = reinterpret_cast<HINSTANCE>(hInst);
20 break;
22 case DLL_PROCESS_DETACH:
23 _Module.m_hInst = NULL;
24 break;
26 case DLL_THREAD_ATTACH:
27 break;
29 case DLL_THREAD_DETACH:
30 break;
33 return TRUE;
37 STDAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID *ppv)
39 // Create the factory object
40 CXMergeFactory *pFactory = new CXMergeFactory();
41 if (pFactory == NULL)
43 *ppv = NULL;
44 return E_OUTOFMEMORY;
47 HRESULT hr = pFactory->QueryInterface(riid, ppv);
48 pFactory->Release();
50 return hr;
54 STDAPI DllCanUnloadNow()
56 if (_Module.GetLockCount() == 0)
57 return S_OK;
59 return S_FALSE;
63 // Utility function to close open keys during registration
64 static _signalRegError(long lRet, HKEY hKey, HKEY hDataKey)
66 if (hKey)
67 ::RegCloseKey(hKey);
70 if (hDataKey)
71 ::RegCloseKey(hDataKey);
73 return HRESULT_FROM_WIN32(lRet);
77 STDAPI DllRegisterServer()
79 HKEY hKey = NULL;
80 HKEY hDataKey = NULL;
82 long lRet = 0;
83 TCHAR sTemp[_MAX_PATH + 1] = "\0";
87 * Following calls create the HKEY_CLASSES_ROOT\CLSID entry for the Writer export filter.
89 * Note that import are export are relative to the WinCE device, so files are
90 * exported to the desktop format.
93 // Get a handle to the CLSID key
94 lRet = ::RegOpenKeyEx(HKEY_CLASSES_ROOT, _T("CLSID"), 0, KEY_ALL_ACCESS, &hKey);
95 if (lRet != ERROR_SUCCESS)
96 return _signalRegError(lRet, hKey, hDataKey);
98 // Create the CLSID key for the XMergeFilter
99 lRet = ::RegCreateKeyEx(hKey, CXMergeFilter::m_pszPSWExportCLSID, 0, _T(""), 0, KEY_ALL_ACCESS, NULL, &hKey, NULL);
100 if (lRet != ERROR_SUCCESS)
101 return _signalRegError(lRet, hKey, hDataKey);
103 lRet = ::RegSetValueEx(hKey, _T(""), 0, REG_SZ, (LPBYTE)CXMergeFilter::m_pszPSWExportShortDesc,
104 (::_tcslen(CXMergeFilter::m_pszPSWExportShortDesc) * sizeof(TCHAR) + (1 * sizeof(TCHAR))));
105 if (lRet != ERROR_SUCCESS)
106 return _signalRegError(lRet, hKey, hDataKey);
109 // Create the DefaultIcon key. For the moment, use one of the Async supplied ones
110 lRet = ::RegCreateKeyEx(hKey, _T("DefaultIcon"), 0, _T(""), 0, KEY_ALL_ACCESS, NULL, &hDataKey, NULL);
111 if (lRet != ERROR_SUCCESS)
112 return _signalRegError(lRet, hKey, hDataKey);
114 lRet = ::RegSetValueEx(hDataKey, NULL, 0, REG_SZ, (LPBYTE)_T("C:\\Program Files\\Microsoft ActiveSync\\pwdcnv.dll,0"),
115 (::_tcslen(_T("C:\\Program Files\\Microsoft ActiveSync\\pwdcnv.dll,0"))
116 * sizeof(TCHAR) + (1 * sizeof(TCHAR))));
117 if (lRet != ERROR_SUCCESS)
118 return _signalRegError(lRet, hKey, hDataKey);
119 ::RegCloseKey(hDataKey); hDataKey = NULL;
121 // Create the InprocServer32 key
122 lRet = ::RegCreateKeyEx(hKey, _T("InProcServer32"), 0, _T(""), 0, KEY_ALL_ACCESS, NULL, &hDataKey, NULL);
123 if (lRet != ERROR_SUCCESS)
124 return _signalRegError(lRet, hKey, hDataKey);
126 lRet = ::RegSetValueEx(hDataKey, _T("ThreadingModel"), 0, REG_SZ, (LPBYTE)_T("Apartment"), 10);
127 if (lRet != ERROR_SUCCESS)
128 return _signalRegError(lRet, hKey, hDataKey);
130 // Create the key for the DLL file. First find the filename of the dll
131 if (!::GetModuleFileName((HMODULE)_Module.m_hInst, sTemp, (_MAX_PATH + 1)))
133 lRet = ::GetLastError();
134 if (lRet != ERROR_SUCCESS)
135 return _signalRegError(lRet, hKey, hDataKey);
139 lRet = ::RegSetValueEx(hDataKey, NULL, 0, REG_SZ, (LPBYTE)sTemp,
140 (::_tcslen(sTemp) * sizeof(TCHAR) + (1 * sizeof(TCHAR))));
141 if (lRet != ERROR_SUCCESS)
142 return _signalRegError(lRet, hKey, hDataKey);
143 ::RegCloseKey(hDataKey); hDataKey = NULL;
146 // Setup the PegasusFilter key values
147 lRet = ::RegCreateKeyEx(hKey, _T("PegasusFilter"), 0, _T(""), 0, KEY_ALL_ACCESS, NULL, &hDataKey, NULL);
148 if (lRet != ERROR_SUCCESS)
149 return _signalRegError(lRet, hKey, hDataKey);
151 lRet = ::RegSetValueEx(hDataKey, _T("Description"), 0, REG_SZ, (LPBYTE)CXMergeFilter::m_pszPSWExportDesc,
152 (::_tcslen(CXMergeFilter::m_pszPSWExportDesc) * sizeof(TCHAR) + (1 * sizeof(TCHAR))));
153 if (lRet != ERROR_SUCCESS)
154 return _signalRegError(lRet, hKey, hDataKey);
157 lRet = ::RegSetValueEx(hDataKey, _T("Export"), 0, REG_SZ, (LPBYTE)_T(""), (1 * sizeof(TCHAR)));
158 if (lRet != ERROR_SUCCESS)
159 return _signalRegError(lRet, hKey, hDataKey);
162 lRet = ::RegSetValueEx(hDataKey, _T("NewExtension"), 0, REG_SZ, (LPBYTE)CXMergeFilter::m_pszPSWExportExt,
163 (::_tcslen(CXMergeFilter::m_pszPSWExportExt) * sizeof(TCHAR) + (1 * sizeof(TCHAR))));
164 if (lRet != ERROR_SUCCESS)
165 return _signalRegError(lRet, hKey, hDataKey);
168 ::RegCloseKey(hKey); hKey = NULL;
169 ::RegCloseKey(hDataKey); hDataKey = NULL;
175 * Following calls create the entries for the filter in
176 * HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows CE Services\Filters
179 lRet = ::RegOpenKeyEx(HKEY_LOCAL_MACHINE, _T("SOFTWARE\\Microsoft\\Windows CE Services\\Filters"),
180 0, KEY_ALL_ACCESS, &hKey);
181 if (lRet != ERROR_SUCCESS)
182 return _signalRegError(lRet, hKey, hDataKey);
184 _snprintf(sTemp, _MAX_PATH + 1, "%c%s\\InstalledFilters\0", '.', CXMergeFilter::m_pszPSWImportExt);
185 lRet = ::RegCreateKeyEx(hKey, _T(sTemp),
186 0, _T(""), 0, KEY_ALL_ACCESS, NULL, &hDataKey, NULL);
187 if (lRet != ERROR_SUCCESS)
188 return _signalRegError(lRet, hKey, hDataKey);
190 lRet = ::RegSetValueEx(hDataKey, CXMergeFilter::m_pszPSWExportCLSID, 0, REG_SZ, (LPBYTE)_T(""), (1 * sizeof(TCHAR)));
191 if (lRet != ERROR_SUCCESS)
192 return _signalRegError(lRet, hKey, hDataKey);
194 ::RegCloseKey(hKey); hKey = NULL;
195 ::RegCloseKey(hDataKey); hDataKey = NULL;
200 * Following calls create the HKEY_CLASSES_ROOT\CLSID entry for the Writer import filter.
202 * Note that import are export are relative to the WinCE device, so files are
203 * exported to the desktop format.
205 // Get a handle to the CLSID key
206 lRet = ::RegOpenKeyEx(HKEY_CLASSES_ROOT, _T("CLSID"), 0, KEY_ALL_ACCESS, &hKey);
207 if (lRet != ERROR_SUCCESS)
208 return _signalRegError(lRet, hKey, hDataKey);
210 // Create the CLSID key for the XMergeFilter
211 lRet = ::RegCreateKeyEx(hKey, CXMergeFilter::m_pszPSWImportCLSID, 0, _T(""), 0, KEY_ALL_ACCESS, NULL, &hKey, NULL);
212 if (lRet != ERROR_SUCCESS)
213 return _signalRegError(lRet, hKey, hDataKey);
215 lRet = ::RegSetValueEx(hKey, _T(""), 0, REG_SZ, (LPBYTE)CXMergeFilter::m_pszPSWImportShortDesc,
216 (::_tcslen(CXMergeFilter::m_pszPSWImportShortDesc) * sizeof(TCHAR) + (1 * sizeof(TCHAR))));
217 if (lRet != ERROR_SUCCESS)
218 return _signalRegError(lRet, hKey, hDataKey);
221 // Create the DefaultIcon key. For the moment, use one of the Async supplied ones
222 lRet = ::RegCreateKeyEx(hKey, _T("DefaultIcon"), 0, _T(""), 0, KEY_ALL_ACCESS, NULL, &hDataKey, NULL);
223 if (lRet != ERROR_SUCCESS)
224 return _signalRegError(lRet, hKey, hDataKey);
226 lRet = ::RegSetValueEx(hDataKey, NULL, 0, REG_SZ, (LPBYTE)_T("C:\\Program Files\\Microsoft ActiveSync\\pwdcnv.dll,0"),
227 (::_tcslen(_T("C:\\Program Files\\Microsoft ActiveSync\\pwdcnv.dll,0"))
228 * sizeof(TCHAR) + (1 * sizeof(TCHAR))));
229 if (lRet != ERROR_SUCCESS)
230 return _signalRegError(lRet, hKey, hDataKey);
231 ::RegCloseKey(hDataKey); hDataKey = NULL;
234 // Create the InprocServer32 key
235 lRet = ::RegCreateKeyEx(hKey, _T("InProcServer32"), 0, _T(""), 0, KEY_ALL_ACCESS, NULL, &hDataKey, NULL);
236 if (lRet != ERROR_SUCCESS)
237 return _signalRegError(lRet, hKey, hDataKey);
239 lRet = ::RegSetValueEx(hDataKey, _T("ThreadingModel"), 0, REG_SZ, (LPBYTE)_T("Apartment"), 10);
240 if (lRet != ERROR_SUCCESS)
241 return _signalRegError(lRet, hKey, hDataKey);
244 // Create the key for the DLL file. First find the filename of the dll
245 if (!::GetModuleFileName((HMODULE)_Module.m_hInst, sTemp, (_MAX_PATH + 1)))
247 lRet = ::GetLastError();
248 if (lRet != ERROR_SUCCESS)
249 return _signalRegError(lRet, hKey, hDataKey);
253 lRet = ::RegSetValueEx(hDataKey, NULL, 0, REG_SZ, (LPBYTE)sTemp,
254 (::_tcslen(sTemp) * sizeof(TCHAR) + (1 * sizeof(TCHAR))));
255 if (lRet != ERROR_SUCCESS)
256 return _signalRegError(lRet, hKey, hDataKey);
257 ::RegCloseKey(hDataKey); hDataKey = NULL;
260 // Setup the PegasusFilter key values
261 lRet = ::RegCreateKeyEx(hKey, _T("PegasusFilter"), 0, _T(""), 0, KEY_ALL_ACCESS, NULL, &hDataKey, NULL);
262 if (lRet != ERROR_SUCCESS)
263 return _signalRegError(lRet, hKey, hDataKey);
265 lRet = ::RegSetValueEx(hDataKey, _T("Description"), 0, REG_SZ, (LPBYTE)CXMergeFilter::m_pszPSWImportDesc,
266 (::_tcslen(CXMergeFilter::m_pszPSWImportDesc) * sizeof(TCHAR) + (1 * sizeof(TCHAR))));
267 if (lRet != ERROR_SUCCESS)
268 return _signalRegError(lRet, hKey, hDataKey);
271 lRet = ::RegSetValueEx(hDataKey, _T("Import"), 0, REG_SZ, (LPBYTE)_T(""), (1 * sizeof(TCHAR)));
272 if (lRet != ERROR_SUCCESS)
273 return _signalRegError(lRet, hKey, hDataKey);
276 lRet = ::RegSetValueEx(hDataKey, _T("NewExtension"), 0, REG_SZ, (LPBYTE)CXMergeFilter::m_pszPSWImportExt,
277 (::_tcslen(CXMergeFilter::m_pszPSWImportExt) * sizeof(TCHAR) + (1 * sizeof(TCHAR))));
278 if (lRet != ERROR_SUCCESS)
279 return _signalRegError(lRet, hKey, hDataKey);
282 ::RegCloseKey(hKey); hKey = NULL;
283 ::RegCloseKey(hDataKey); hDataKey = NULL;
287 * Following calls create the entries for the filter in
288 * HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows CE Services\Filters
290 lRet = ::RegOpenKeyEx(HKEY_LOCAL_MACHINE, _T("SOFTWARE\\Microsoft\\Windows CE Services\\Filters"),
291 0, KEY_ALL_ACCESS, &hKey);
292 if (lRet != ERROR_SUCCESS)
293 return _signalRegError(lRet, hKey, hDataKey);
295 // Add in defaults for import and export
296 _snprintf(sTemp, _MAX_PATH +1, "%c%s\0", '.', CXMergeFilter::m_pszPSWExportExt);
297 lRet = ::RegCreateKeyEx(hKey, _T(sTemp), 0, _T(""), 0, KEY_ALL_ACCESS, NULL, &hDataKey, NULL);
298 if (lRet != ERROR_SUCCESS)
299 return _signalRegError(lRet, hKey, hDataKey);
301 lRet = ::RegSetValueEx(hDataKey, _T("DefaultImport"), 0, REG_SZ,
302 (LPBYTE)CXMergeFilter::m_pszPSWImportCLSID,
303 (::_tcslen(CXMergeFilter::m_pszPSWImportDesc) * sizeof(TCHAR) + (1 * sizeof(TCHAR))));
304 if (lRet != ERROR_SUCCESS)
305 return _signalRegError(lRet, hKey, hDataKey);
308 lRet = ::RegSetValueEx(hDataKey, _T("DefaultExport"), 0, REG_SZ, (LPBYTE)_T("Binary Copy"),
309 (::_tcslen(_T("Binary Copy")) * sizeof(TCHAR) + (1 * sizeof(TCHAR))));
310 if (lRet != ERROR_SUCCESS)
311 return _signalRegError(lRet, hKey, hDataKey);
313 ::RegCloseKey(hDataKey);
315 // Update registered filters
316 _snprintf(sTemp, _MAX_PATH + 1, "%c%s\\InstalledFilters\0", '.', CXMergeFilter::m_pszPSWExportExt);
317 lRet = ::RegCreateKeyEx(hKey, _T(sTemp),
318 0, _T(""), 0, KEY_ALL_ACCESS, NULL, &hDataKey, NULL);
319 if (lRet != ERROR_SUCCESS)
320 return _signalRegError(lRet, hKey, hDataKey);
323 lRet = ::RegSetValueEx(hDataKey, CXMergeFilter::m_pszPSWImportCLSID, 0, REG_SZ, (LPBYTE)_T(""), (1 * sizeof(TCHAR)));
324 if (lRet != ERROR_SUCCESS)
325 return _signalRegError(lRet, hKey, hDataKey);
327 ::RegCloseKey(hKey); hKey = NULL;
328 ::RegCloseKey(hDataKey); hDataKey = NULL;
333 * Following calls create the HKEY_CLASSES_ROOT\CLSID entry for the Calc export filter.
335 * Note that import are export are relative to the WinCE device, so files are
336 * exported to the desktop format.
339 // Get a handle to the CLSID key
340 lRet = ::RegOpenKeyEx(HKEY_CLASSES_ROOT, _T("CLSID"), 0, KEY_ALL_ACCESS, &hKey);
341 if (lRet != ERROR_SUCCESS)
342 return _signalRegError(lRet, hKey, hDataKey);
344 // Create the CLSID key for the XMerge Filter
345 lRet = ::RegCreateKeyEx(hKey, CXMergeFilter::m_pszPXLExportCLSID, 0, _T(""),
346 0, KEY_ALL_ACCESS, NULL, &hKey, NULL);
347 if (lRet != ERROR_SUCCESS)
348 return _signalRegError(lRet, hKey, hDataKey);
350 lRet = ::RegSetValueEx(hKey, _T(""), 0, REG_SZ, (LPBYTE)CXMergeFilter::m_pszPXLExportShortDesc,
351 (::_tcslen(CXMergeFilter::m_pszPXLExportShortDesc) * sizeof(TCHAR) + (1 * sizeof(TCHAR))));
352 if (lRet != ERROR_SUCCESS)
353 return _signalRegError(lRet, hKey, hDataKey);
356 // Create the DefaultIcon key. For the moment, use one of the Async supplied ones
357 lRet = ::RegCreateKeyEx(hKey, _T("DefaultIcon"), 0, _T(""), 0, KEY_ALL_ACCESS, NULL, &hDataKey, NULL);
358 if (lRet != ERROR_SUCCESS)
359 return _signalRegError(lRet, hKey, hDataKey);
361 lRet = ::RegSetValueEx(hDataKey, NULL, 0, REG_SZ, (LPBYTE)_T("C:\\Program Files\\Microsoft ActiveSync\\pwdcnv.dll,0"),
362 (::_tcslen(_T("C:\\Program Files\\Microsoft ActiveSync\\pwdcnv.dll,0"))
363 * sizeof(TCHAR) + (1 * sizeof(TCHAR))));
364 if (lRet != ERROR_SUCCESS)
365 return _signalRegError(lRet, hKey, hDataKey);
366 ::RegCloseKey(hDataKey); hDataKey = NULL;
369 // Create the InprocServer32 key
370 lRet = ::RegCreateKeyEx(hKey, _T("InProcServer32"), 0, _T(""), 0, KEY_ALL_ACCESS, NULL, &hDataKey, NULL);
371 if (lRet != ERROR_SUCCESS)
372 return _signalRegError(lRet, hKey, hDataKey);
374 lRet = ::RegSetValueEx(hDataKey, _T("ThreadingModel"), 0, REG_SZ, (LPBYTE)_T("Apartment"), 10);
375 if (lRet != ERROR_SUCCESS)
376 return _signalRegError(lRet, hKey, hDataKey);
379 // Create the key for the DLL file. First find the filename of the dll
380 if (!::GetModuleFileName((HMODULE)_Module.m_hInst, sTemp, (_MAX_PATH + 1)))
382 lRet = ::GetLastError();
383 if (lRet != ERROR_SUCCESS)
384 return _signalRegError(lRet, hKey, hDataKey);
388 lRet = ::RegSetValueEx(hDataKey, NULL, 0, REG_SZ, (LPBYTE)sTemp,
389 (::_tcslen(sTemp) * sizeof(TCHAR) + (1 * sizeof(TCHAR))));
390 if (lRet != ERROR_SUCCESS)
391 return _signalRegError(lRet, hKey, hDataKey);
392 ::RegCloseKey(hDataKey); hDataKey = NULL;
395 // Setup the PegasusFilter key values
396 lRet = ::RegCreateKeyEx(hKey, _T("PegasusFilter"), 0, _T(""), 0, KEY_ALL_ACCESS, NULL, &hDataKey, NULL);
397 if (lRet != ERROR_SUCCESS)
398 return _signalRegError(lRet, hKey, hDataKey);
400 lRet = ::RegSetValueEx(hDataKey, _T("Description"), 0, REG_SZ, (LPBYTE)CXMergeFilter::m_pszPXLExportDesc,
401 (::_tcslen(CXMergeFilter::m_pszPXLExportDesc) * sizeof(TCHAR) + (1 * sizeof(TCHAR))));
402 if (lRet != ERROR_SUCCESS)
403 return _signalRegError(lRet, hKey, hDataKey);
406 lRet = ::RegSetValueEx(hDataKey, _T("Export"), 0, REG_SZ, (LPBYTE)_T(""), (1 * sizeof(TCHAR)));
407 if (lRet != ERROR_SUCCESS)
408 return _signalRegError(lRet, hKey, hDataKey);
411 lRet = ::RegSetValueEx(hDataKey, _T("NewExtension"), 0, REG_SZ, (LPBYTE)CXMergeFilter::m_pszPXLExportExt,
412 (::_tcslen(CXMergeFilter::m_pszPXLExportExt) * sizeof(TCHAR) + (1 * sizeof(TCHAR))));
413 if (lRet != ERROR_SUCCESS)
414 return _signalRegError(lRet, hKey, hDataKey);
417 ::RegCloseKey(hKey); hKey = NULL;
418 ::RegCloseKey(hDataKey); hDataKey = NULL;
424 * Following calls create the entries for the filter in
425 * HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows CE Services\Filters
428 lRet = ::RegOpenKeyEx(HKEY_LOCAL_MACHINE, _T("SOFTWARE\\Microsoft\\Windows CE Services\\Filters"),
429 0, KEY_ALL_ACCESS, &hKey);
430 if (lRet != ERROR_SUCCESS)
431 return _signalRegError(lRet, hKey, hDataKey);
433 _snprintf(sTemp, _MAX_PATH + 1, "%c%s\\InstalledFilters\0", '.', CXMergeFilter::m_pszPXLImportExt);
434 lRet = ::RegCreateKeyEx(hKey, _T(sTemp),
435 0, _T(""), 0, KEY_ALL_ACCESS, NULL, &hDataKey, NULL);
436 if (lRet != ERROR_SUCCESS)
437 return _signalRegError(lRet, hKey, hDataKey);
439 lRet = ::RegSetValueEx(hDataKey, CXMergeFilter::m_pszPXLExportCLSID, 0, REG_SZ, (LPBYTE)_T(""), (1 * sizeof(TCHAR)));
440 if (lRet != ERROR_SUCCESS)
441 return _signalRegError(lRet, hKey, hDataKey);
443 ::RegCloseKey(hKey); hKey = NULL;
444 ::RegCloseKey(hDataKey); hDataKey = NULL;
449 * Following calls create the HKEY_CLASSES_ROOT\CLSID entry for the Calc import filter.
451 * Note that import are export are relative to the WinCE device, so files are
452 * exported to the desktop format.
454 // Get a handle to the CLSID key
455 lRet = ::RegOpenKeyEx(HKEY_CLASSES_ROOT, _T("CLSID"), 0, KEY_ALL_ACCESS, &hKey);
456 if (lRet != ERROR_SUCCESS)
457 return _signalRegError(lRet, hKey, hDataKey);
460 // Create the CLSID key for the XMergeFilter
461 lRet = ::RegCreateKeyEx(hKey, CXMergeFilter::m_pszPXLImportCLSID, 0, _T(""), 0, KEY_ALL_ACCESS, NULL, &hKey, NULL);
462 if (lRet != ERROR_SUCCESS)
463 return _signalRegError(lRet, hKey, hDataKey);
465 lRet = ::RegSetValueEx(hKey, _T(""), 0, REG_SZ, (LPBYTE)CXMergeFilter::m_pszPXLImportShortDesc,
466 (::_tcslen(CXMergeFilter::m_pszPXLImportShortDesc) * sizeof(TCHAR) + (1 * sizeof(TCHAR))));
467 if (lRet != ERROR_SUCCESS)
468 return _signalRegError(lRet, hKey, hDataKey);
470 // Create the DefaultIcon key. For the moment, use one of the Async supplied ones
471 lRet = ::RegCreateKeyEx(hKey, _T("DefaultIcon"), 0, _T(""), 0, KEY_ALL_ACCESS, NULL, &hDataKey, NULL);
472 if (lRet != ERROR_SUCCESS)
473 return _signalRegError(lRet, hKey, hDataKey);
475 lRet = ::RegSetValueEx(hDataKey, NULL, 0, REG_SZ, (LPBYTE)_T("C:\\Program Files\\Microsoft ActiveSync\\pwdcnv.dll,0"),
476 (::_tcslen(_T("C:\\Program Files\\Microsoft ActiveSync\\pwdcnv.dll,0"))
477 * sizeof(TCHAR) + (1 * sizeof(TCHAR))));
478 if (lRet != ERROR_SUCCESS)
479 return _signalRegError(lRet, hKey, hDataKey);
480 ::RegCloseKey(hDataKey); hDataKey = NULL;
483 // Create the InprocServer32 key
484 lRet = ::RegCreateKeyEx(hKey, _T("InProcServer32"), 0, _T(""), 0, KEY_ALL_ACCESS, NULL, &hDataKey, NULL);
485 if (lRet != ERROR_SUCCESS)
486 return _signalRegError(lRet, hKey, hDataKey);
488 lRet = ::RegSetValueEx(hDataKey, _T("ThreadingModel"), 0, REG_SZ, (LPBYTE)_T("Apartment"), 10);
489 if (lRet != ERROR_SUCCESS)
490 return _signalRegError(lRet, hKey, hDataKey);
493 // Create the key for the DLL file. First find the filename of the dll
494 if (!::GetModuleFileName((HMODULE)_Module.m_hInst, sTemp, (_MAX_PATH + 1)))
496 lRet = ::GetLastError();
497 if (lRet != ERROR_SUCCESS)
498 return _signalRegError(lRet, hKey, hDataKey);
502 lRet = ::RegSetValueEx(hDataKey, NULL, 0, REG_SZ, (LPBYTE)sTemp,
503 (::_tcslen(sTemp) * sizeof(TCHAR) + (1 * sizeof(TCHAR))));
504 if (lRet != ERROR_SUCCESS)
505 return _signalRegError(lRet, hKey, hDataKey);
506 ::RegCloseKey(hDataKey); hDataKey = NULL;
509 // Setup the PegasusFilter key values
510 lRet = ::RegCreateKeyEx(hKey, _T("PegasusFilter"), 0, _T(""), 0, KEY_ALL_ACCESS, NULL, &hDataKey, NULL);
511 if (lRet != ERROR_SUCCESS)
512 return _signalRegError(lRet, hKey, hDataKey);
514 lRet = ::RegSetValueEx(hDataKey, _T("Description"), 0, REG_SZ, (LPBYTE)CXMergeFilter::m_pszPXLImportDesc,
515 (::_tcslen(CXMergeFilter::m_pszPXLImportDesc) * sizeof(TCHAR) + (1 * sizeof(TCHAR))));
516 if (lRet != ERROR_SUCCESS)
517 return _signalRegError(lRet, hKey, hDataKey);
520 lRet = ::RegSetValueEx(hDataKey, _T("Import"), 0, REG_SZ, (LPBYTE)_T(""), (1 * sizeof(TCHAR)));
521 if (lRet != ERROR_SUCCESS)
522 return _signalRegError(lRet, hKey, hDataKey);
525 lRet = ::RegSetValueEx(hDataKey, _T("NewExtension"), 0, REG_SZ, (LPBYTE)CXMergeFilter::m_pszPXLImportExt,
526 (::_tcslen(CXMergeFilter::m_pszPXLImportExt) * sizeof(TCHAR) + (1 * sizeof(TCHAR))));
527 if (lRet != ERROR_SUCCESS)
528 return _signalRegError(lRet, hKey, hDataKey);
531 ::RegCloseKey(hKey); hKey = NULL;
532 ::RegCloseKey(hDataKey); hDataKey = NULL;
537 * Following calls create the entries for the filter in
538 * HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows CE Services\Filters
540 lRet = ::RegOpenKeyEx(HKEY_LOCAL_MACHINE, _T("SOFTWARE\\Microsoft\\Windows CE Services\\Filters"),
541 0, KEY_ALL_ACCESS, &hKey);
542 if (lRet != ERROR_SUCCESS)
543 return _signalRegError(lRet, hKey, hDataKey);
545 // Add in defaults for import and export
546 _snprintf(sTemp, _MAX_PATH +1, "%c%s\0", '.', CXMergeFilter::m_pszPXLExportExt);
547 lRet = ::RegCreateKeyEx(hKey, _T(sTemp), 0, _T(""), 0, KEY_ALL_ACCESS, NULL, &hDataKey, NULL);
548 if (lRet != ERROR_SUCCESS)
549 return _signalRegError(lRet, hKey, hDataKey);
551 lRet = ::RegSetValueEx(hDataKey, _T("DefaultImport"), 0, REG_SZ,
552 (LPBYTE)CXMergeFilter::m_pszPXLImportCLSID,
553 (::_tcslen(CXMergeFilter::m_pszPSWImportDesc) * sizeof(TCHAR) + (1 * sizeof(TCHAR))));
554 if (lRet != ERROR_SUCCESS)
555 return _signalRegError(lRet, hKey, hDataKey);
558 lRet = ::RegSetValueEx(hDataKey, _T("DefaultExport"), 0, REG_SZ, (LPBYTE)_T("Binary Copy"),
559 (::_tcslen(_T("Binary Copy")) * sizeof(TCHAR) + (1 * sizeof(TCHAR))));
560 if (lRet != ERROR_SUCCESS)
561 return _signalRegError(lRet, hKey, hDataKey);
563 ::RegCloseKey(hDataKey);
565 // Update registered filters
568 _snprintf(sTemp, _MAX_PATH + 1, "%c%s\\InstalledFilters\0", '.', CXMergeFilter::m_pszPXLExportExt);
569 lRet = ::RegCreateKeyEx(hKey, _T(sTemp),
570 0, _T(""), 0, KEY_ALL_ACCESS, NULL, &hDataKey, NULL);
571 if (lRet != ERROR_SUCCESS)
572 return _signalRegError(lRet, hKey, hDataKey);
574 lRet = ::RegSetValueEx(hDataKey, CXMergeFilter::m_pszPXLImportCLSID, 0, REG_SZ, (LPBYTE)_T(""), (1 * sizeof(TCHAR)));
575 if (lRet != ERROR_SUCCESS)
576 return _signalRegError(lRet, hKey, hDataKey);
578 ::RegCloseKey(hKey); hKey = NULL;
579 ::RegCloseKey(hDataKey); hDataKey = NULL;
583 return HRESULT_FROM_WIN32(lRet);
587 STDAPI DllUnregisterServer()
589 long lRet = 0;
590 HKEY hKey = NULL;
591 HKEY hDataKey = NULL;
593 TCHAR szClassName[_MAX_PATH] = "\0";
594 TCHAR szKeyName[_MAX_PATH] = "\0";
595 DWORD dwClassName = _MAX_PATH;
596 DWORD dwKeyName = _MAX_PATH;
599 * Remove HKEY_CLASS_ROOT\CLSID\{XXX} entry for the export and import filters
601 * Windows 95/98/Me allow one step deletion of a key and all subkeys.
602 * Windows NT/2000/XP do not so the subkeys must be deleted individually.
604 lRet = ::RegOpenKeyEx(HKEY_CLASSES_ROOT, _T("CLSID"), 0, KEY_ALL_ACCESS, &hKey);
605 if (lRet != ERROR_SUCCESS)
606 return _signalRegError(lRet, hKey, hDataKey);
609 // First up, the Writer export filter
610 lRet = ::RegOpenKeyEx(hKey, CXMergeFilter::m_pszPSWExportCLSID, 0, KEY_ALL_ACCESS, &hDataKey);
611 if (lRet != ERROR_SUCCESS)
612 return _signalRegError(lRet, hKey, hDataKey);
615 while ((lRet = ::RegEnumKeyEx(hDataKey, 0, szKeyName, &dwKeyName, 0, szClassName, &dwClassName, NULL))
616 != ERROR_NO_MORE_ITEMS)
618 lRet = ::RegDeleteKey(hDataKey, szKeyName);
620 ::lstrcpy(szKeyName, "\0");
621 ::lstrcpy(szClassName, "\0");
623 dwClassName = _MAX_PATH;
624 dwKeyName = _MAX_PATH;
627 ::RegCloseKey(hDataKey); hDataKey = NULL;
629 lRet = ::RegDeleteKey(hKey, CXMergeFilter::m_pszPSWExportCLSID);
630 if (lRet != ERROR_SUCCESS && lRet != ERROR_FILE_NOT_FOUND)
631 return _signalRegError(lRet, hKey, hDataKey);
635 // Next, the Writer import filter
636 lRet = ::RegOpenKeyEx(hKey, CXMergeFilter::m_pszPSWImportCLSID, 0, KEY_ALL_ACCESS, &hDataKey);
637 if (lRet != ERROR_SUCCESS)
638 return _signalRegError(lRet, hKey, hDataKey);
641 while ((lRet = ::RegEnumKeyEx(hDataKey, 0, szKeyName, &dwKeyName, 0, szClassName, &dwClassName, NULL))
642 != ERROR_NO_MORE_ITEMS)
644 lRet = ::RegDeleteKey(hDataKey, szKeyName);
646 ::lstrcpy(szKeyName, "\0");
647 ::lstrcpy(szClassName, "\0");
649 dwClassName = _MAX_PATH;
650 dwKeyName = _MAX_PATH;
653 ::RegCloseKey(hDataKey); hDataKey = NULL;
655 lRet = ::RegDeleteKey(hKey, CXMergeFilter::m_pszPSWImportCLSID);
656 if (lRet != ERROR_SUCCESS && lRet != ERROR_FILE_NOT_FOUND)
657 return _signalRegError(lRet, hKey, hDataKey);
660 // Next up, the Calc export filter
661 lRet = ::RegOpenKeyEx(hKey, CXMergeFilter::m_pszPXLExportCLSID, 0, KEY_ALL_ACCESS, &hDataKey);
662 if (lRet != ERROR_SUCCESS)
663 return _signalRegError(lRet, hKey, hDataKey);
666 while ((lRet = ::RegEnumKeyEx(hDataKey, 0, szKeyName, &dwKeyName, 0, szClassName, &dwClassName, NULL))
667 != ERROR_NO_MORE_ITEMS)
669 lRet = ::RegDeleteKey(hDataKey, szKeyName);
671 ::lstrcpy(szKeyName, "\0");
672 ::lstrcpy(szClassName, "\0");
674 dwClassName = _MAX_PATH;
675 dwKeyName = _MAX_PATH;
678 ::RegCloseKey(hDataKey); hDataKey = NULL;
680 lRet = ::RegDeleteKey(hKey, CXMergeFilter::m_pszPXLExportCLSID);
681 if (lRet != ERROR_SUCCESS && lRet != ERROR_FILE_NOT_FOUND)
682 return _signalRegError(lRet, hKey, hDataKey);
685 // Next, the Calc import filter
686 lRet = ::RegOpenKeyEx(hKey, CXMergeFilter::m_pszPXLImportCLSID, 0, KEY_ALL_ACCESS, &hDataKey);
687 if (lRet != ERROR_SUCCESS)
688 return _signalRegError(lRet, hKey, hDataKey);
691 while ((lRet = ::RegEnumKeyEx(hDataKey, 0, szKeyName, &dwKeyName, 0, szClassName, &dwClassName, NULL))
692 != ERROR_NO_MORE_ITEMS)
694 lRet = ::RegDeleteKey(hDataKey, szKeyName);
696 ::lstrcpy(szKeyName, "\0");
697 ::lstrcpy(szClassName, "\0");
699 dwClassName = _MAX_PATH;
700 dwKeyName = _MAX_PATH;
703 ::RegCloseKey(hDataKey); hDataKey = NULL;
705 lRet = ::RegDeleteKey(hKey, CXMergeFilter::m_pszPXLImportCLSID);
706 if (lRet != ERROR_SUCCESS && lRet != ERROR_FILE_NOT_FOUND)
707 return _signalRegError(lRet, hKey, hDataKey);
709 ::RegCloseKey(hKey); hKey = NULL;
714 * Remove the HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows CE Services\Filters
716 lRet = ::RegOpenKeyEx(HKEY_LOCAL_MACHINE, _T("SOFTWARE\\Microsoft\\Windows CE Services\\Filters"),
717 0, KEY_ALL_ACCESS, &hKey);
718 if (lRet != ERROR_SUCCESS)
719 return _signalRegError(lRet, hKey, hDataKey);
722 // Remove the Writer export filter from the Writer import file extension subkey.
723 _snprintf(szKeyName, _MAX_PATH, ".%s\\InstalledFilters", CXMergeFilter::m_pszPSWImportExt);
724 lRet = ::RegOpenKeyEx(hKey, _T(szKeyName), 0, KEY_ALL_ACCESS, &hDataKey);
725 if (lRet != ERROR_SUCCESS)
726 return _signalRegError(lRet, hKey, hDataKey);
728 lRet = ::RegDeleteValue(hDataKey, CXMergeFilter::m_pszPSWExportCLSID);
729 if (lRet != ERROR_SUCCESS)
730 return _signalRegError(lRet, hKey, hDataKey);
732 ::lstrcpyn(szKeyName, "\0", _MAX_PATH);
733 ::RegCloseKey(hDataKey); hDataKey = NULL;
736 // Remove the Writer import filter from the Writer export file extension subkey.
737 _snprintf(szKeyName, _MAX_PATH, ".%s\\InstalledFilters", CXMergeFilter::m_pszPSWExportExt);
738 lRet = ::RegOpenKeyEx(hKey, _T(szKeyName), 0, KEY_ALL_ACCESS, &hDataKey);
739 if (lRet != ERROR_SUCCESS)
740 return _signalRegError(lRet, hKey, hDataKey);
742 lRet = ::RegDeleteValue(hDataKey, CXMergeFilter::m_pszPSWImportCLSID);
743 if (lRet != ERROR_SUCCESS)
744 return _signalRegError(lRet, hKey, hDataKey);
746 ::lstrcpyn(szKeyName, "\0", _MAX_PATH);
747 ::RegCloseKey(hDataKey); hDataKey = NULL;
750 // Make Binary Copy the default for Writer export file extension subkey DefaultImport
751 _snprintf(szKeyName, _MAX_PATH, ".%s\0", CXMergeFilter::m_pszPSWExportExt);
752 lRet = ::RegOpenKeyEx(hKey, _T(szKeyName), 0, KEY_ALL_ACCESS, &hDataKey);
753 if (lRet != ERROR_SUCCESS)
754 return _signalRegError(lRet, hKey, hDataKey);
756 lRet = ::RegSetValueEx(hDataKey, _T("DefaultImport"), 0, REG_SZ, (LPBYTE)_T("Binary Copy"),
757 (::_tcslen(_T("Binary Copy")) * sizeof(TCHAR) + (1 * sizeof(TCHAR))));
758 if (lRet != ERROR_SUCCESS)
759 return _signalRegError(lRet, hKey, hDataKey);
761 ::lstrcpyn(szKeyName, "\0", _MAX_PATH);
762 ::RegCloseKey(hDataKey); hDataKey = NULL;
765 // Remove the Calc export filter from the Calc import file extension subkey.
766 _snprintf(szKeyName, _MAX_PATH, ".%s\\InstalledFilters", CXMergeFilter::m_pszPXLImportExt);
767 lRet = ::RegOpenKeyEx(hKey, _T(szKeyName), 0, KEY_ALL_ACCESS, &hDataKey);
768 if (lRet != ERROR_SUCCESS)
769 return _signalRegError(lRet, hKey, hDataKey);
771 lRet = ::RegDeleteValue(hDataKey, CXMergeFilter::m_pszPXLExportCLSID);
772 if (lRet != ERROR_SUCCESS)
773 return _signalRegError(lRet, hKey, hDataKey);
775 ::lstrcpyn(szKeyName, "\0", _MAX_PATH);
776 ::RegCloseKey(hDataKey); hDataKey = NULL;
778 // Remove the Calc import filter from the Calc export file extension subkey.
779 _snprintf(szKeyName, _MAX_PATH, ".%s\\InstalledFilters", CXMergeFilter::m_pszPXLExportExt);
780 lRet = ::RegOpenKeyEx(hKey, _T(szKeyName), 0, KEY_ALL_ACCESS, &hDataKey);
781 if (lRet != ERROR_SUCCESS)
782 return _signalRegError(lRet, hKey, hDataKey);
784 lRet = ::RegDeleteValue(hDataKey, CXMergeFilter::m_pszPXLImportCLSID);
785 if (lRet != ERROR_SUCCESS)
786 return _signalRegError(lRet, hKey, hDataKey);
788 ::lstrcpyn(szKeyName, "\0", _MAX_PATH);
789 ::RegCloseKey(hDataKey); hDataKey = NULL;
792 // Make Binary Copy the default for Calc export file extension subkey DefaultImport
793 _snprintf(szKeyName, _MAX_PATH, ".%s\0", CXMergeFilter::m_pszPXLExportExt);
794 lRet = ::RegOpenKeyEx(hKey, _T(szKeyName), 0, KEY_ALL_ACCESS, &hDataKey);
795 if (lRet != ERROR_SUCCESS)
796 return _signalRegError(lRet, hKey, hDataKey);
798 lRet = ::RegSetValueEx(hDataKey, _T("DefaultImport"), 0, REG_SZ, (LPBYTE)_T("Binary Copy"),
799 (::_tcslen(_T("Binary Copy")) * sizeof(TCHAR) + (1 * sizeof(TCHAR))));
800 if (lRet != ERROR_SUCCESS)
801 return _signalRegError(lRet, hKey, hDataKey);
803 ::lstrcpyn(szKeyName, "\0", _MAX_PATH);
804 ::RegCloseKey(hDataKey); hDataKey = NULL;
808 ::RegCloseKey(hKey); hKey = NULL;
810 return HRESULT_FROM_WIN32(lRet);
814 //////////////////////////////////////////////////////////////////////
815 // CXMergeSyncModule methods
816 //////////////////////////////////////////////////////////////////////
817 CXMergeSyncModule::CXMergeSyncModule ()
821 CXMergeSyncModule::~CXMergeSyncModule ()
825 long CXMergeSyncModule::LockServer(BOOL fLock)
827 if(fLock)
828 return ::InterlockedIncrement(&m_lLocks);
829 else
830 return ::InterlockedDecrement(&m_lLocks);
833 long CXMergeSyncModule::GetLockCount()
835 return m_lLocks + m_lObjs;