update dev300-m58
[ooovba.git] / extensions / source / activex / main / so_activex.cpp
blob51a1db1427744c3fddfbc49e109f11faf45965a7
1 // so_activex.cpp : Implementation of DLL Exports.
4 // Note: Proxy/Stub Information
5 // To build a separate proxy/stub DLL,
6 // run nmake -f so_activexps.mk in the project directory.
8 #include "stdio.h"
9 #include "stdafx2.h"
10 #include "resource.h"
11 #include <initguid.h>
12 #include "so_activex.h"
14 #include "so_activex_i.c"
15 #include "SOActiveX.h"
17 #include <comphelper\documentconstants.hxx>
19 // #define MY_DEBUG 1
21 CComModule _Module;
23 BEGIN_OBJECT_MAP(ObjectMap)
24 OBJECT_ENTRY(CLSID_SOActiveX, CSOActiveX)
25 END_OBJECT_MAP()
27 /////////////////////////////////////////////////////////////////////////////
28 // DLL Entry Point
30 extern "C"
31 BOOL WINAPI DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID /*lpReserved*/)
33 if (dwReason == DLL_PROCESS_ATTACH)
35 _Module.Init(ObjectMap, hInstance, &LIBID_SO_ACTIVEXLib);
36 DisableThreadLibraryCalls(hInstance);
38 else if (dwReason == DLL_PROCESS_DETACH)
39 _Module.Term();
40 return TRUE; // ok
43 /////////////////////////////////////////////////////////////////////////////
44 // Used to determine whether the DLL can be unloaded by OLE
46 STDAPI DllCanUnloadNow(void)
48 return (_Module.GetLockCount()==0) ? S_OK : S_FALSE;
51 /////////////////////////////////////////////////////////////////////////////
52 // Returns a class factory to create an object of the requested type
54 STDAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID* ppv)
56 return _Module.GetClassObject(rclsid, riid, ppv);
59 /////////////////////////////////////////////////////////////////////////////
60 // DllRegisterServer - Adds entries to the system registry
62 // for now database component and chart are always installed
63 #define SUPPORTED_EXT_NUM 30
64 const char* aFileExt[] = { ".vor",
65 ".sds", ".sda", ".sdd", ".sdp", ".sdc", ".sdw", ".smf",
66 ".stw", ".stc", ".sti", ".std",
67 ".sxw", ".sxc", ".sxi", ".sxd", ".sxg", ".sxm",
68 ".ott", ".otg", ".otp", ".ots", ".otf",
69 ".odt", ".oth", ".odm", ".odg", ".odp", ".ods", ".odf"};
70 const char* aMimeType[] = {
71 "application/vnd.stardivision.writer",
73 "application/vnd.stardivision.chart",
74 "application/vnd.stardivision.draw",
75 "application/vnd.stardivision.impress",
76 "application/vnd.stardivision.impress-packed",
77 "application/vnd.stardivision.calc",
78 "application/vnd.stardivision.writer",
79 "application/vnd.stardivision.math",
81 MIMETYPE_VND_SUN_XML_WRITER_TEMPLATE_ASCII,
82 MIMETYPE_VND_SUN_XML_CALC_TEMPLATE_ASCII,
83 MIMETYPE_VND_SUN_XML_IMPRESS_TEMPLATE_ASCII,
84 MIMETYPE_VND_SUN_XML_DRAW_TEMPLATE_ASCII,
86 MIMETYPE_VND_SUN_XML_WRITER_ASCII,
87 MIMETYPE_VND_SUN_XML_CALC_ASCII,
88 MIMETYPE_VND_SUN_XML_IMPRESS_ASCII,
89 MIMETYPE_VND_SUN_XML_DRAW_ASCII,
90 MIMETYPE_VND_SUN_XML_WRITER_GLOBAL_ASCII,
91 MIMETYPE_VND_SUN_XML_MATH_ASCII,
93 MIMETYPE_OASIS_OPENDOCUMENT_TEXT_TEMPLATE_ASCII,
94 MIMETYPE_OASIS_OPENDOCUMENT_DRAWING_TEMPLATE_ASCII,
95 MIMETYPE_OASIS_OPENDOCUMENT_PRESENTATION_TEMPLATE_ASCII,
96 MIMETYPE_OASIS_OPENDOCUMENT_SPREADSHEET_TEMPLATE_ASCII,
97 MIMETYPE_OASIS_OPENDOCUMENT_FORMULA_TEMPLATE_ASCII,
99 MIMETYPE_OASIS_OPENDOCUMENT_TEXT_ASCII,
100 MIMETYPE_OASIS_OPENDOCUMENT_TEXT_WEB_ASCII,
101 MIMETYPE_OASIS_OPENDOCUMENT_TEXT_GLOBAL_ASCII,
102 MIMETYPE_OASIS_OPENDOCUMENT_DRAWING_ASCII,
103 MIMETYPE_OASIS_OPENDOCUMENT_PRESENTATION_ASCII,
104 MIMETYPE_OASIS_OPENDOCUMENT_SPREADSHEET_ASCII,
105 MIMETYPE_OASIS_OPENDOCUMENT_FORMULA_ASCII };
107 const int nForModes[] = { 16,
108 1, 2, 4, 4, 8, 16, 32,
109 16, 8, 4, 2,
110 16, 8, 4, 2, 16, 32,
111 16, 2, 4, 8, 32,
112 16, 16, 16, 2, 4, 8, 32 };
114 const char* aClassID = "{67F2A879-82D5-4A6D-8CC5-FFB3C114B69D}";
115 const char* aTypeLib = "{61FA3F13-8061-4796-B055-3697ED28CB38}";
117 // ISOComWindowPeer interface information
118 const char* aInterIDWinPeer = "{BF5D10F3-8A10-4A0B-B150-2B6AA2D7E118}";
119 const char* aProxyStubWinPeer = "{00020424-0000-0000-C000-000000000046}";
121 // ISODispatchInterceptor interface information
122 const char* aInterIDDispInt = "{9337694C-B27D-4384-95A4-9D8E0EABC9E5}";
123 const char* aProxyStubDispInt = "{00020424-0000-0000-C000-000000000046}";
125 // ISOActionsApproval interface information
126 const char* aInterIDActApprove = "{029E9F1E-2B3F-4297-9160-8197DE7ED54F}";
127 const char* aProxyStubActApprove = "{00020424-0000-0000-C000-000000000046}";
129 // The following prefix is required for HKEY_LOCAL_MACHINE and HKEY_CURRENT_USER ( not for HKEY_CLASSES_ROOT )
130 const char* aLocalPrefix = "Software\\Classes\\";
132 BOOL createKey( HKEY hkey,
133 const char* aKeyToCreate,
134 const char* aValue = NULL,
135 const char* aChildName = NULL,
136 const char* aChildValue = NULL )
138 HKEY hkey1;
140 return ( ERROR_SUCCESS == RegCreateKey( hkey, aKeyToCreate, &hkey1 )
141 && ( !aValue || ERROR_SUCCESS == RegSetValueEx( hkey1,
142 "",
144 REG_SZ,
145 (const BYTE*)aValue,
146 strlen( aValue ) ) )
147 && ( !aChildName || ERROR_SUCCESS == RegSetValueEx( hkey1,
148 aChildName,
150 REG_SZ,
151 (const BYTE*)aChildValue,
152 strlen( aChildValue ) ) )
153 && ERROR_SUCCESS == RegCloseKey( hkey1 ) );
157 STDAPI DllUnregisterServerNative( int nMode, BOOL bForAllUsers );
158 STDAPI DllRegisterServerNative( int nMode, BOOL bForAllUsers, const char* pActiveXPath )
160 BOOL aResult = FALSE;
162 HKEY hkey = NULL;
163 HKEY hkey1 = NULL;
164 HKEY hkey2 = NULL;
165 HKEY hkey3 = NULL;
166 HKEY hkey4 = NULL;
167 char aSubKey[513];
168 int ind;
169 const char* aPrefix = aLocalPrefix; // bForAllUsers ? "" : aLocalPrefix;
171 char pActiveXPath101[1024];
172 char pPrCatalogPath[1019];
175 // In case SO7 is installed for this user he can have local registry entries that will prevent him from
176 // using SO8 ActiveX control. The fix is just to clean up the local entries related to ActiveX control.
177 // Unfortunately it can be done only for the user who installs the office.
178 if ( bForAllUsers )
179 DllUnregisterServerNative( nMode, sal_False );
181 #ifdef MY_DEBUG
182 MessageBoxA(NULL, pActiveXPath, "Library Path, ( from library )", MB_OK | MB_ICONINFORMATION);
183 #endif
185 if ( pActiveXPath )
187 sprintf( pActiveXPath101, "%s, 101", pActiveXPath );
189 int nPrCatLength = strlen( pActiveXPath ) - sizeof( "so_activex.dll" ) + 1;
190 strncpy( pPrCatalogPath, pActiveXPath, nPrCatLength );
191 pPrCatalogPath[ nPrCatLength ] = 0;
194 wsprintf( aSubKey, "%sCLSID\\%s", aPrefix, aClassID );
195 aResult =
196 ( ERROR_SUCCESS == RegCreateKey( bForAllUsers ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER, aSubKey, &hkey )
197 && ERROR_SUCCESS == RegSetValueEx( hkey, "", 0, REG_SZ, (const BYTE*)"SOActiveX Class", 17 )
198 && createKey( hkey, "Control" )
199 && createKey( hkey, "EnableFullPage" )
200 && createKey( hkey, "InprocServer32", pActiveXPath, "ThreadingModel", "Apartment" )
201 && createKey( hkey, "MiscStatus", "0" )
202 && createKey( hkey, "MiscStatus\\1", "131473" )
203 && createKey( hkey, "ProgID", "so_activex.SOActiveX.1" )
204 && createKey( hkey, "Programmable" )
205 && createKey( hkey, "ToolboxBitmap32", pActiveXPath101 )
206 && createKey( hkey, "TypeLib", aTypeLib )
207 && createKey( hkey, "Version", "1.0" )
208 && createKey( hkey, "VersionIndependentProgID", "so_activex.SOActiveX" )
209 && ERROR_SUCCESS == RegCloseKey( hkey )
210 && ERROR_SUCCESS == RegCreateKey( bForAllUsers ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER, aPrefix, &hkey )
211 && createKey( hkey, "so_activex.SOActiveX", "SOActiveX Class" )
212 && ERROR_SUCCESS == RegCreateKey( hkey, "so_activex.SOActiveX", &hkey1 )
213 && createKey( hkey1, "CLSID", aClassID )
214 && createKey( hkey1, "CurVer", "so_activex.SOActiveX.1" )
215 && ERROR_SUCCESS == RegCloseKey( hkey1 )
216 && createKey( hkey, "so_activex.SOActiveX.1", "SOActiveX Class" )
217 && ERROR_SUCCESS == RegCreateKey( hkey, "so_activex.SOActiveX.1", &hkey1 )
218 && createKey( hkey1, "CLSID", aClassID )
219 && ERROR_SUCCESS == RegCloseKey( hkey1 )
220 && ERROR_SUCCESS == RegCreateKey( hkey, "TypeLib", &hkey1 )
221 && ERROR_SUCCESS == RegCreateKey( hkey1, aTypeLib, &hkey2 )
222 && createKey( hkey2, "1.0", "wrap_activex 1.0 Type Library" )
223 && ERROR_SUCCESS == RegCreateKey( hkey2, "1.0", &hkey3 )
224 && ERROR_SUCCESS == RegCreateKey( hkey3, "0", &hkey4 )
225 && createKey( hkey4, "win32", pActiveXPath )
226 && ERROR_SUCCESS == RegCloseKey( hkey4 )
227 && createKey( hkey3, "FLAGS", "0" )
228 && createKey( hkey3, "HELPDIR", pPrCatalogPath )
229 && ERROR_SUCCESS == RegCloseKey( hkey3 )
230 && ERROR_SUCCESS == RegCloseKey( hkey2 )
231 && ERROR_SUCCESS == RegCloseKey( hkey1 )
232 && ERROR_SUCCESS == RegCreateKey( hkey, "Interface", &hkey1 )
233 && createKey( hkey1, aInterIDWinPeer, "ISOComWindowPeer" )
234 && ERROR_SUCCESS == RegCreateKey( hkey1, aInterIDWinPeer, &hkey2 )
235 && createKey( hkey2, "ProxyStubClsid", aProxyStubWinPeer )
236 && createKey( hkey2, "ProxyStubClsid32", aProxyStubWinPeer )
237 && createKey( hkey2, "TypeLib", aTypeLib, "Version", "1.0" )
238 && ERROR_SUCCESS == RegCloseKey( hkey2 )
239 && createKey( hkey1, aInterIDActApprove, "ISOActionsApproval" )
240 && ERROR_SUCCESS == RegCreateKey( hkey1, aInterIDActApprove, &hkey2 )
241 && createKey( hkey2, "ProxyStubClsid", aProxyStubActApprove )
242 && createKey( hkey2, "ProxyStubClsid32", aProxyStubActApprove )
243 && createKey( hkey2, "TypeLib", aTypeLib, "Version", "1.0" )
244 && ERROR_SUCCESS == RegCloseKey( hkey2 )
245 && createKey( hkey1, aInterIDDispInt, "ISODispatchInterceptor" )
246 && ERROR_SUCCESS == RegCreateKey( hkey1, aInterIDDispInt, &hkey2 )
247 && createKey( hkey2, "ProxyStubClsid", aProxyStubDispInt )
248 && createKey( hkey2, "ProxyStubClsid32", aProxyStubDispInt )
249 && createKey( hkey2, "TypeLib", aTypeLib, "Version", "1.0" )
250 && ERROR_SUCCESS == RegCloseKey( hkey2 )
251 && ERROR_SUCCESS == RegCloseKey( hkey1 )
252 && ERROR_SUCCESS == RegCloseKey( hkey ) );
254 hkey = hkey1 = hkey2 = hkey3 = hkey4 = NULL;
258 for( ind = 0; ind < SUPPORTED_EXT_NUM && aResult; ind++ )
260 if( nForModes[ind] & nMode )
262 wsprintf( aSubKey, "%sMIME\\DataBase\\Content Type\\%s", aPrefix, aMimeType[ind] );
263 if ( ERROR_SUCCESS != RegCreateKey(bForAllUsers ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER, aSubKey, &hkey)
264 // || ERROR_SUCCESS != RegSetValueEx(hkey, "Extension", 0, REG_SZ,
265 // (const BYTE *)aFileExt[ind], strlen( aFileExt[ind] ) )
266 || ERROR_SUCCESS != RegSetValueEx(hkey, "CLSID", 0, REG_SZ,
267 (const BYTE *)aClassID, strlen(aClassID)) )
268 aResult = FALSE;
270 if( hkey )
271 RegCloseKey(hkey),hkey= NULL;
274 wsprintf( aSubKey, "%s%s", aPrefix, aFileExt[ind] );
275 if ( ERROR_SUCCESS != RegCreateKey(bForAllUsers ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER, aSubKey, &hkey)
276 || ERROR_SUCCESS != RegSetValueEx(hkey, "Content Type", 0, REG_SZ,
277 (const BYTE *)aMimeType[ind], strlen( aMimeType[ind] ) ) )
278 aResult = FALSE;
279 if( hkey )
280 RegCloseKey(hkey),hkey= NULL;
285 wsprintf( aSubKey, "%sCLSID\\%s", aPrefix, aClassID );
286 if ( aResult && ERROR_SUCCESS == RegOpenKey(bForAllUsers ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER, aSubKey, &hkey) )
288 for( ind = 0; ind < SUPPORTED_EXT_NUM; ind++ )
290 wsprintf( aSubKey, "EnableFullPage\\%s", aFileExt[ind] );
291 if ( ERROR_SUCCESS != RegCreateKey( hkey, aSubKey, &hkey1 ) )
292 aResult = FALSE;
294 if ( hkey1 )
295 RegCloseKey(hkey1),hkey1= NULL;
298 else
299 aResult = FALSE;
301 if ( hkey )
302 RegCloseKey(hkey),hkey= NULL;
304 return aResult;
307 /////////////////////////////////////////////////////////////////////////////
308 // DllUnregisterServer - Removes entries from the system registry
310 STDAPI DllUnregisterServerNative( int nMode, BOOL bForAllUsers )
312 HKEY hkey = NULL;
313 BOOL fErr = FALSE;
314 char aSubKey[513];
315 const char* aPrefix = aLocalPrefix; // bForAllUsers ? "" : aLocalPrefix;
317 for( int ind = 0; ind < SUPPORTED_EXT_NUM; ind++ )
319 if( nForModes[ind] & nMode )
321 DWORD nSubKeys = 0, nValues = 0;
322 wsprintf( aSubKey, "%sMIME\\DataBase\\Content Type\\%s", aPrefix, aMimeType[ind] );
323 if ( ERROR_SUCCESS != RegCreateKey(bForAllUsers ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER, aSubKey, &hkey) )
324 fErr = TRUE;
325 else
327 if ( ERROR_SUCCESS != RegDeleteValue( hkey, "CLSID" ) )
328 fErr = TRUE;
330 if ( ERROR_SUCCESS != RegQueryInfoKey( hkey, NULL, NULL, NULL,
331 &nSubKeys, NULL, NULL,
332 &nValues, NULL, NULL, NULL, NULL ) )
334 RegCloseKey( hkey ), hkey = NULL;
335 fErr = TRUE;
337 else
339 RegCloseKey( hkey ), hkey = NULL;
340 if ( !nSubKeys && !nValues )
341 SHDeleteKey( bForAllUsers ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER, aSubKey );
345 wsprintf( aSubKey, "%s%s", aPrefix, aFileExt[ind] );
346 if ( ERROR_SUCCESS != RegCreateKey(bForAllUsers ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER, aSubKey, &hkey) )
347 fErr = TRUE;
348 else
350 if ( ERROR_SUCCESS != RegQueryInfoKey( hkey, NULL, NULL, NULL,
351 &nSubKeys, NULL, NULL,
352 &nValues, NULL, NULL, NULL, NULL ) )
354 RegCloseKey( hkey ), hkey = NULL;
355 fErr = TRUE;
357 else
359 RegCloseKey( hkey ), hkey = NULL;
360 if ( !nSubKeys && !nValues )
361 SHDeleteKey( bForAllUsers ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER, aSubKey );
367 wsprintf( aSubKey, "%sCLSID\\%s", aPrefix, aClassID );
368 if( ERROR_SUCCESS != SHDeleteKey( bForAllUsers ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER, aSubKey ) )
369 fErr = TRUE;
371 wsprintf( aSubKey, "%sso_activex.SOActiveX", aPrefix );
372 if( ERROR_SUCCESS != SHDeleteKey( bForAllUsers ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER, aSubKey ) )
373 fErr = TRUE;
375 wsprintf( aSubKey, "%sso_activex.SOActiveX.1", aPrefix );
376 if( ERROR_SUCCESS != SHDeleteKey( bForAllUsers ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER, aSubKey ) )
377 fErr = TRUE;
379 wsprintf( aSubKey, "%s\\TypeLib\\%s", aPrefix, aTypeLib );
380 if( ERROR_SUCCESS != SHDeleteKey( bForAllUsers ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER, aSubKey ) )
381 fErr = TRUE;
383 wsprintf( aSubKey, "%s\\Interface\\%s", aPrefix, aInterIDWinPeer );
384 if( ERROR_SUCCESS != SHDeleteKey( bForAllUsers ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER, aSubKey ) )
385 fErr = TRUE;
387 wsprintf( aSubKey, "%s\\Interface\\%s", aPrefix, aInterIDDispInt );
388 if( ERROR_SUCCESS != SHDeleteKey( bForAllUsers ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER, aSubKey ) )
389 fErr = TRUE;
391 wsprintf( aSubKey, "%s\\Interface\\%s", aPrefix, aInterIDActApprove );
392 if( ERROR_SUCCESS != SHDeleteKey( bForAllUsers ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER, aSubKey ) )
393 fErr = TRUE;
395 return !fErr;
398 /////////////////////////////////////////////////////////////////////////////
399 // DllRegisterServerDoc - Adds entries to the system registry
401 #define SUPPORTED_MSEXT_NUM 7
402 const char* aMSFileExt[] = { ".dot", ".doc", ".xlt", ".xls", ".pot", ".ppt", ".pps" };
403 const char* aMSMimeType[] = { "application/msword",
404 "application/msword",
405 "application/msexcell",
406 "application/msexcell",
407 "application/mspowerpoint",
408 "application/mspowerpoint",
409 "application/mspowerpoint" };
410 const int nForMSModes[] = { 1, 1, 2, 2, 4, 4, 4 };
412 STDAPI DllUnregisterServerDoc( int nMode, BOOL bForAllUsers );
413 STDAPI DllRegisterServerDoc( int nMode, BOOL bForAllUsers )
415 BOOL aResult = TRUE;
417 HKEY hkey = NULL;
418 HKEY hkey1 = NULL;
419 char aSubKey[513];
420 int ind;
421 const char* aPrefix = aLocalPrefix; // bForAllUsers ? "" : aLocalPrefix;
423 // In case SO7 is installed for this user he can have local registry entries that will prevent him from
424 // using SO8 ActiveX control. The fix is just to clean up the local entries related to ActiveX control.
425 // Unfortunately it can be done only for the user who installs the office.
426 if ( bForAllUsers )
427 DllUnregisterServerDoc( nMode, sal_False );
429 for( ind = 0; ind < SUPPORTED_MSEXT_NUM && aResult; ind++ )
431 if( nForMSModes[ind] & nMode )
433 wsprintf( aSubKey, "%sMIME\\DataBase\\Content Type\\%s", aPrefix, aMSMimeType[ind] );
434 if ( ERROR_SUCCESS != RegCreateKey(bForAllUsers ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER, aSubKey, &hkey)
435 || ERROR_SUCCESS != RegSetValueEx(hkey, "Extension", 0, REG_SZ,
436 (const BYTE *)aMSFileExt[ind], strlen( aMSFileExt[ind] ) )
437 || ERROR_SUCCESS != RegSetValueEx(hkey, "CLSID", 0, REG_SZ,
438 (const BYTE *)aClassID, strlen(aClassID)) )
439 aResult = FALSE;
441 if( hkey )
442 RegCloseKey(hkey),hkey= NULL;
444 wsprintf( aSubKey, "%s%s", aPrefix, aMSFileExt[ind] );
445 if ( ERROR_SUCCESS != RegCreateKey(bForAllUsers ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER, aSubKey, &hkey)
446 || ERROR_SUCCESS != RegSetValueEx(hkey, "Content Type", 0, REG_SZ,
447 (const BYTE *)aMSMimeType[ind], strlen( aMSMimeType[ind] ) ) )
448 aResult = FALSE;
450 if( hkey )
451 RegCloseKey(hkey),hkey= NULL;
455 wsprintf( aSubKey, "%sCLSID\\%s", aPrefix, aClassID );
456 if ( aResult && ERROR_SUCCESS == RegCreateKey( bForAllUsers ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER, aSubKey, &hkey )
457 && createKey( hkey, "EnableFullPage" ) )
459 for( ind = 0; ind < SUPPORTED_MSEXT_NUM; ind++ )
461 if( nForMSModes[ind] & nMode )
463 wsprintf( aSubKey, "EnableFullPage\\%s", aMSFileExt[ind] );
464 if ( ERROR_SUCCESS != RegCreateKey( hkey, aSubKey, &hkey1 ) )
465 aResult = FALSE;
467 if ( hkey1 )
468 RegCloseKey(hkey1),hkey1= NULL;
472 else
473 aResult = FALSE;
475 if ( hkey )
476 RegCloseKey(hkey),hkey= NULL;
478 return aResult;
483 /////////////////////////////////////////////////////////////////////////////
484 // DllUnregisterServerDoc - Removes entries from the system registry
486 STDAPI DllUnregisterServerDoc( int nMode, BOOL bForAllUsers )
488 HKEY hkey = NULL;
489 BOOL fErr = FALSE;
490 char aSubKey[513];
491 const char* aPrefix = aLocalPrefix; // bForAllUsers ? "" : aLocalPrefix;
493 for( int ind = 0; ind < SUPPORTED_MSEXT_NUM; ind++ )
495 if( nForMSModes[ind] & nMode )
497 DWORD nSubKeys = 0, nValues = 0;
499 wsprintf( aSubKey, "%sMIME\\DataBase\\Content Type\\%s", aPrefix, aMSMimeType[ind] );
500 if ( ERROR_SUCCESS != RegCreateKey(bForAllUsers ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER, aSubKey, &hkey) )
501 fErr = TRUE;
502 else
504 if ( ERROR_SUCCESS != RegDeleteValue( hkey, "Extension" ) )
505 fErr = TRUE;
507 if ( ERROR_SUCCESS != RegDeleteValue( hkey, "CLSID" ) )
508 fErr = TRUE;
510 if ( ERROR_SUCCESS != RegQueryInfoKey( hkey, NULL, NULL, NULL,
511 &nSubKeys, NULL, NULL,
512 &nValues, NULL, NULL, NULL, NULL ) )
514 RegCloseKey( hkey ), hkey = NULL;
515 fErr = TRUE;
517 else
519 RegCloseKey( hkey ), hkey = NULL;
520 if ( !nSubKeys && !nValues )
521 SHDeleteKey( bForAllUsers ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER, aSubKey );
525 wsprintf( aSubKey, "%s%s", aPrefix, aMSFileExt[ind] );
526 if ( ERROR_SUCCESS != RegCreateKey(bForAllUsers ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER, aSubKey, &hkey) )
527 fErr = TRUE;
528 else
530 if ( ERROR_SUCCESS != RegDeleteValue( hkey, "Content Type" ) )
531 fErr = TRUE;
533 if ( ERROR_SUCCESS != RegQueryInfoKey( hkey, NULL, NULL, NULL,
534 &nSubKeys, NULL, NULL,
535 &nValues, NULL, NULL, NULL, NULL ) )
537 RegCloseKey( hkey ), hkey = NULL;
538 fErr = TRUE;
540 else
542 RegCloseKey( hkey ), hkey = NULL;
543 if ( !nSubKeys && !nValues )
544 SHDeleteKey( bForAllUsers ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER, aSubKey );
550 return !fErr;
553 STDAPI DllRegisterServer( void )
555 char pActiveXPath[1019];
556 HRESULT aResult = E_FAIL;
558 HMODULE aCurModule = GetModuleHandleA( "so_activex.dll" );
559 if( aCurModule && GetModuleFileNameA( aCurModule, pActiveXPath, 1019 ) )
561 aResult = DllRegisterServerNative( 31, TRUE, pActiveXPath );
562 if( SUCCEEDED( aResult ) )
563 aResult = DllRegisterServerDoc( 31, TRUE );
564 else
566 aResult = DllRegisterServerNative( 31, FALSE, pActiveXPath );
567 if( SUCCEEDED( aResult ) )
568 aResult = DllRegisterServerDoc( 31, FALSE );
572 return aResult;
575 STDAPI DllUnregisterServer( void )
577 DllUnregisterServerDoc( 63, FALSE );
578 DllUnregisterServerNative( 63, FALSE );
579 DllUnregisterServerDoc( 63, TRUE );
580 return DllUnregisterServerNative( 63, TRUE );