summaryrefslogtreecommitdiff
path: root/extensions/source/activex/main/so_activex.cpp
blob: 057406a0f1f2c2eaa3e3b105cc5369817958e7bc (plain)
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
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
// so_activex.cpp : Implementation of DLL Exports.


// Note: Proxy/Stub Information
//      To build a separate proxy/stub DLL,
//      run nmake -f so_activexps.mk in the project directory.

#include "stdio.h"
#include "stdafx2.h"
#include "resource.h"
#include <initguid.h>
#include "so_activex.h"

#include "so_activex_i.c"
#include "SOActiveX.h"

#include <comphelper\documentconstants.hxx>

// #define MY_DEBUG 1

CComModule _Module;

BEGIN_OBJECT_MAP(ObjectMap)
OBJECT_ENTRY(CLSID_SOActiveX, CSOActiveX)
END_OBJECT_MAP()

/////////////////////////////////////////////////////////////////////////////
// DLL Entry Point

extern "C"
BOOL WINAPI DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID /*lpReserved*/)
{
    if (dwReason == DLL_PROCESS_ATTACH)
    {
        _Module.Init(ObjectMap, hInstance, &LIBID_SO_ACTIVEXLib);
        DisableThreadLibraryCalls(hInstance);
    }
    else if (dwReason == DLL_PROCESS_DETACH)
        _Module.Term();
    return TRUE;    // ok
}

/////////////////////////////////////////////////////////////////////////////
// Used to determine whether the DLL can be unloaded by OLE

STDAPI DllCanUnloadNow(void)
{
    return (_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)
{
    return _Module.GetClassObject(rclsid, riid, ppv);
}

/////////////////////////////////////////////////////////////////////////////
// DllRegisterServer - Adds entries to the system registry

// for now database component and chart are always installed
#define SUPPORTED_EXT_NUM 30
const char* aFileExt[] = { ".vor",
                           ".sds", ".sda", ".sdd", ".sdp", ".sdc", ".sdw", ".smf",
                           ".stw", ".stc", ".sti", ".std",
                           ".sxw", ".sxc", ".sxi", ".sxd", ".sxg", ".sxm",
                           ".ott", ".otg", ".otp", ".ots", ".otf",
                           ".odt", ".oth", ".odm", ".odg", ".odp", ".ods", ".odf"};
const char* aMimeType[] = {
                          "application/vnd.stardivision.writer",

                          "application/vnd.stardivision.chart",
                          "application/vnd.stardivision.draw",
                          "application/vnd.stardivision.impress",
                          "application/vnd.stardivision.impress-packed",
                          "application/vnd.stardivision.calc",
                          "application/vnd.stardivision.writer",
                          "application/vnd.stardivision.math",

                          MIMETYPE_VND_SUN_XML_WRITER_TEMPLATE_ASCII,
                          MIMETYPE_VND_SUN_XML_CALC_TEMPLATE_ASCII,
                          MIMETYPE_VND_SUN_XML_IMPRESS_TEMPLATE_ASCII,
                          MIMETYPE_VND_SUN_XML_DRAW_TEMPLATE_ASCII,

                          MIMETYPE_VND_SUN_XML_WRITER_ASCII,
                          MIMETYPE_VND_SUN_XML_CALC_ASCII,
                          MIMETYPE_VND_SUN_XML_IMPRESS_ASCII,
                          MIMETYPE_VND_SUN_XML_DRAW_ASCII,
                          MIMETYPE_VND_SUN_XML_WRITER_GLOBAL_ASCII,
                          MIMETYPE_VND_SUN_XML_MATH_ASCII,

                          MIMETYPE_OASIS_OPENDOCUMENT_TEXT_TEMPLATE_ASCII,
                          MIMETYPE_OASIS_OPENDOCUMENT_DRAWING_TEMPLATE_ASCII,
                          MIMETYPE_OASIS_OPENDOCUMENT_PRESENTATION_TEMPLATE_ASCII,
                          MIMETYPE_OASIS_OPENDOCUMENT_SPREADSHEET_TEMPLATE_ASCII,
                          MIMETYPE_OASIS_OPENDOCUMENT_FORMULA_TEMPLATE_ASCII,

                          MIMETYPE_OASIS_OPENDOCUMENT_TEXT_ASCII,
                          MIMETYPE_OASIS_OPENDOCUMENT_TEXT_WEB_ASCII,
                          MIMETYPE_OASIS_OPENDOCUMENT_TEXT_GLOBAL_ASCII,
                          MIMETYPE_OASIS_OPENDOCUMENT_DRAWING_ASCII,
                          MIMETYPE_OASIS_OPENDOCUMENT_PRESENTATION_ASCII,
                          MIMETYPE_OASIS_OPENDOCUMENT_SPREADSHEET_ASCII,
                          MIMETYPE_OASIS_OPENDOCUMENT_FORMULA_ASCII };

const int nForModes[] = { 16,
                           1,  2,  4,  4,  8, 16, 32,
                          16,  8,  4,  2,
                          16,  8,  4,  2, 16, 32,
                          16,  2,  4,  8, 32,
                          16, 16, 16,  2,  4,  8, 32 };

const char* aClassID = "{67F2A879-82D5-4A6D-8CC5-FFB3C114B69D}";
const char* aTypeLib = "{61FA3F13-8061-4796-B055-3697ED28CB38}";

// ISOComWindowPeer interface information
const char* aInterIDWinPeer = "{BF5D10F3-8A10-4A0B-B150-2B6AA2D7E118}";
const char* aProxyStubWinPeer = "{00020424-0000-0000-C000-000000000046}";

// ISODispatchInterceptor interface information
const char* aInterIDDispInt = "{9337694C-B27D-4384-95A4-9D8E0EABC9E5}";
const char* aProxyStubDispInt = "{00020424-0000-0000-C000-000000000046}";

// ISOActionsApproval interface information
const char* aInterIDActApprove = "{029E9F1E-2B3F-4297-9160-8197DE7ED54F}";
const char* aProxyStubActApprove = "{00020424-0000-0000-C000-000000000046}";

// The following prefix is required for HKEY_LOCAL_MACHINE and HKEY_CURRENT_USER ( not for HKEY_CLASSES_ROOT )
const char* aLocalPrefix = "Software\\Classes\\";

BOOL createKey( HKEY hkey,
                const char* aKeyToCreate,
                const char* aValue = NULL,
                const char* aChildName = NULL,
                const char* aChildValue = NULL )
{
    HKEY hkey1;

    return ( ERROR_SUCCESS == RegCreateKey( hkey, aKeyToCreate, &hkey1 )
           && ( !aValue || ERROR_SUCCESS == RegSetValueEx( hkey1,
                                                           "",
                                                           0,
                                                           REG_SZ,
                                                           (const BYTE*)aValue,
                                                           strlen( aValue ) ) )
           && ( !aChildName || ERROR_SUCCESS == RegSetValueEx( hkey1,
                                                               aChildName,
                                                               0,
                                                               REG_SZ,
                                                               (const BYTE*)aChildValue,
                                                               strlen( aChildValue ) ) )
           && ERROR_SUCCESS == RegCloseKey( hkey1 ) );

}

STDAPI DllUnregisterServerNative( int nMode, BOOL bForAllUsers );
STDAPI DllRegisterServerNative( int nMode, BOOL bForAllUsers, const char* pActiveXPath )
{
    BOOL aResult = FALSE;

    HKEY        hkey = NULL;
    HKEY        hkey1 = NULL;
    HKEY        hkey2 = NULL;
    HKEY        hkey3 = NULL;
    HKEY        hkey4 = NULL;
    char        aSubKey[513];
    int         ind;
    const char* aPrefix = aLocalPrefix; // bForAllUsers ? "" : aLocalPrefix;

    char pActiveXPath101[1024];
    char pPrCatalogPath[1019];


    // In case SO7 is installed for this user he can have local registry entries that will prevent him from
    // using SO8 ActiveX control. The fix is just to clean up the local entries related to ActiveX control.
    // Unfortunately it can be done only for the user who installs the office.
    if ( bForAllUsers )
        DllUnregisterServerNative( nMode, sal_False );

#ifdef MY_DEBUG
    MessageBoxA(NULL, pActiveXPath, "Library Path, ( from library )", MB_OK | MB_ICONINFORMATION);
#endif

    if ( pActiveXPath )
    {
        sprintf( pActiveXPath101, "%s, 101", pActiveXPath );

        int nPrCatLength = strlen( pActiveXPath ) - sizeof( "so_activex.dll" ) + 1;
        strncpy( pPrCatalogPath, pActiveXPath, nPrCatLength );
        pPrCatalogPath[ nPrCatLength ] = 0;

        {
            wsprintf( aSubKey, "%sCLSID\\%s", aPrefix, aClassID );
            aResult =
                ( ERROR_SUCCESS == RegCreateKey( bForAllUsers ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER, aSubKey, &hkey )
                    && ERROR_SUCCESS == RegSetValueEx( hkey, "", 0, REG_SZ, (const BYTE*)"SOActiveX Class", 17 )
                    && createKey( hkey, "Control" )
                    && createKey( hkey, "EnableFullPage" )
                    && createKey( hkey, "InprocServer32", pActiveXPath, "ThreadingModel", "Apartment" )
                    && createKey( hkey, "MiscStatus", "0" )
                    && createKey( hkey, "MiscStatus\\1", "131473" )
                    && createKey( hkey, "ProgID", "so_activex.SOActiveX.1" )
                    && createKey( hkey, "Programmable" )
                    && createKey( hkey, "ToolboxBitmap32", pActiveXPath101 )
                    && createKey( hkey, "TypeLib", aTypeLib )
                    && createKey( hkey, "Version", "1.0" )
                    && createKey( hkey, "VersionIndependentProgID", "so_activex.SOActiveX" )
                && ERROR_SUCCESS == RegCloseKey( hkey )
                && ERROR_SUCCESS == RegCreateKey( bForAllUsers ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER, aPrefix, &hkey )
                    && createKey( hkey, "so_activex.SOActiveX", "SOActiveX Class" )
                    && ERROR_SUCCESS == RegCreateKey( hkey, "so_activex.SOActiveX", &hkey1 )
                        && createKey( hkey1, "CLSID", aClassID )
                        && createKey( hkey1, "CurVer", "so_activex.SOActiveX.1" )
                    && ERROR_SUCCESS == RegCloseKey( hkey1 )
                    && createKey( hkey, "so_activex.SOActiveX.1", "SOActiveX Class" )
                    && ERROR_SUCCESS == RegCreateKey( hkey, "so_activex.SOActiveX.1", &hkey1 )
                        && createKey( hkey1, "CLSID", aClassID )
                    && ERROR_SUCCESS == RegCloseKey( hkey1 )
                    && ERROR_SUCCESS == RegCreateKey( hkey, "TypeLib", &hkey1 )
                        && ERROR_SUCCESS == RegCreateKey( hkey1, aTypeLib, &hkey2 )
                            && createKey( hkey2, "1.0", "wrap_activex 1.0 Type Library" )
                            && ERROR_SUCCESS == RegCreateKey( hkey2, "1.0", &hkey3 )
                                && ERROR_SUCCESS == RegCreateKey( hkey3, "0", &hkey4 )
                                    && createKey( hkey4, "win32", pActiveXPath )
                                && ERROR_SUCCESS == RegCloseKey( hkey4 )
                                && createKey( hkey3, "FLAGS", "0" )
                                && createKey( hkey3, "HELPDIR", pPrCatalogPath )
                            && ERROR_SUCCESS == RegCloseKey( hkey3 )
                        && ERROR_SUCCESS == RegCloseKey( hkey2 )
                    && ERROR_SUCCESS == RegCloseKey( hkey1 )
                    && ERROR_SUCCESS == RegCreateKey( hkey, "Interface", &hkey1 )
                        && createKey( hkey1, aInterIDWinPeer, "ISOComWindowPeer" )
                        && ERROR_SUCCESS == RegCreateKey( hkey1, aInterIDWinPeer, &hkey2 )
                            && createKey( hkey2, "ProxyStubClsid", aProxyStubWinPeer )
                            && createKey( hkey2, "ProxyStubClsid32", aProxyStubWinPeer )
                            && createKey( hkey2, "TypeLib", aTypeLib, "Version", "1.0" )
                        && ERROR_SUCCESS == RegCloseKey( hkey2 )
                        && createKey( hkey1, aInterIDActApprove, "ISOActionsApproval" )
                        && ERROR_SUCCESS == RegCreateKey( hkey1, aInterIDActApprove, &hkey2 )
                            && createKey( hkey2, "ProxyStubClsid", aProxyStubActApprove )
                            && createKey( hkey2, "ProxyStubClsid32", aProxyStubActApprove )
                            && createKey( hkey2, "TypeLib", aTypeLib, "Version", "1.0" )
                        && ERROR_SUCCESS == RegCloseKey( hkey2 )
                        && createKey( hkey1, aInterIDDispInt, "ISODispatchInterceptor" )
                        && ERROR_SUCCESS == RegCreateKey( hkey1, aInterIDDispInt, &hkey2 )
                            && createKey( hkey2, "ProxyStubClsid", aProxyStubDispInt )
                            && createKey( hkey2, "ProxyStubClsid32", aProxyStubDispInt )
                            && createKey( hkey2, "TypeLib", aTypeLib, "Version", "1.0" )
                        && ERROR_SUCCESS == RegCloseKey( hkey2 )
                    && ERROR_SUCCESS == RegCloseKey( hkey1 )
                && ERROR_SUCCESS == RegCloseKey( hkey ) );

            hkey = hkey1 = hkey2 = hkey3 = hkey4 = NULL;
        }
    }

    for( ind = 0; ind < SUPPORTED_EXT_NUM && aResult; ind++ )
    {
        if( nForModes[ind] & nMode )
        {
            wsprintf( aSubKey, "%sMIME\\DataBase\\Content Type\\%s", aPrefix, aMimeType[ind] );
            if ( ERROR_SUCCESS != RegCreateKey(bForAllUsers ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER, aSubKey, &hkey)
//              || ERROR_SUCCESS != RegSetValueEx(hkey, "Extension", 0, REG_SZ,
//               (const BYTE *)aFileExt[ind], strlen( aFileExt[ind] ) )
              || ERROR_SUCCESS != RegSetValueEx(hkey, "CLSID", 0, REG_SZ,
                 (const BYTE *)aClassID, strlen(aClassID)) )
                    aResult = FALSE;

            if( hkey )
                RegCloseKey(hkey),hkey= NULL;

/*
            wsprintf( aSubKey, "%s%s", aPrefix, aFileExt[ind] );
            if ( ERROR_SUCCESS != RegCreateKey(bForAllUsers ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER, aSubKey, &hkey)
              || ERROR_SUCCESS != RegSetValueEx(hkey, "Content Type", 0, REG_SZ,
                 (const BYTE *)aMimeType[ind], strlen( aMimeType[ind] ) ) )
                    aResult = FALSE;
            if( hkey )
                RegCloseKey(hkey),hkey= NULL;
*/
        }
    }

    wsprintf( aSubKey, "%sCLSID\\%s", aPrefix, aClassID );
    if ( aResult && ERROR_SUCCESS == RegOpenKey(bForAllUsers ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER, aSubKey, &hkey) )
    {
           for( ind = 0; ind < SUPPORTED_EXT_NUM; ind++ )
           {
               wsprintf( aSubKey, "EnableFullPage\\%s", aFileExt[ind] );
               if ( ERROR_SUCCESS != RegCreateKey( hkey, aSubKey, &hkey1 ) )
                   aResult = FALSE;

            if ( hkey1 )
                   RegCloseKey(hkey1),hkey1= NULL;
         }
    }
    else
        aResult = FALSE;

    if ( hkey )
           RegCloseKey(hkey),hkey= NULL;

    return aResult;
}

/////////////////////////////////////////////////////////////////////////////
// DllUnregisterServer - Removes entries from the system registry

STDAPI DllUnregisterServerNative( int nMode, BOOL bForAllUsers )
{
    HKEY        hkey = NULL;
    BOOL        fErr = FALSE;
    char        aSubKey[513];
    const char* aPrefix = aLocalPrefix; // bForAllUsers ? "" : aLocalPrefix;

      for( int ind = 0; ind < SUPPORTED_EXT_NUM; ind++ )
    {
        if( nForModes[ind] & nMode )
        {
            DWORD nSubKeys = 0, nValues = 0;
               wsprintf( aSubKey, "%sMIME\\DataBase\\Content Type\\%s", aPrefix, aMimeType[ind] );
               if ( ERROR_SUCCESS != RegCreateKey(bForAllUsers ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER, aSubKey, &hkey) )
                fErr = TRUE;
            else
            {
                   if ( ERROR_SUCCESS != RegDeleteValue( hkey, "CLSID" ) )
                    fErr = TRUE;

                   if ( ERROR_SUCCESS != RegQueryInfoKey(  hkey, NULL, NULL, NULL,
                                                    &nSubKeys, NULL, NULL,
                                                    &nValues, NULL, NULL, NULL, NULL ) )
                {
                    RegCloseKey( hkey ), hkey = NULL;
                    fErr = TRUE;
                }
                else
                {
                    RegCloseKey( hkey ), hkey = NULL;
                    if ( !nSubKeys && !nValues )
                        SHDeleteKey( bForAllUsers ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER, aSubKey );
                }
            }

               wsprintf( aSubKey, "%s%s", aPrefix, aFileExt[ind] );
               if ( ERROR_SUCCESS != RegCreateKey(bForAllUsers ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER, aSubKey, &hkey) )
                fErr = TRUE;
            else
            {
                   if ( ERROR_SUCCESS != RegQueryInfoKey(  hkey, NULL, NULL, NULL,
                                                    &nSubKeys, NULL, NULL,
                                                    &nValues, NULL, NULL, NULL, NULL ) )
                {
                    RegCloseKey( hkey ), hkey = NULL;
                    fErr = TRUE;
                }
                else
                {
                    RegCloseKey( hkey ), hkey = NULL;
                    if ( !nSubKeys && !nValues )
                        SHDeleteKey( bForAllUsers ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER, aSubKey );
                }
            }
        }
    }

    wsprintf( aSubKey, "%sCLSID\\%s", aPrefix, aClassID );
    if( ERROR_SUCCESS != SHDeleteKey( bForAllUsers ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER, aSubKey ) )
           fErr = TRUE;

    wsprintf( aSubKey, "%sso_activex.SOActiveX", aPrefix );
    if( ERROR_SUCCESS != SHDeleteKey( bForAllUsers ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER, aSubKey ) )
           fErr = TRUE;

    wsprintf( aSubKey, "%sso_activex.SOActiveX.1", aPrefix );
    if( ERROR_SUCCESS != SHDeleteKey( bForAllUsers ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER, aSubKey ) )
           fErr = TRUE;

    wsprintf( aSubKey, "%s\\TypeLib\\%s", aPrefix, aTypeLib );
    if( ERROR_SUCCESS != SHDeleteKey( bForAllUsers ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER, aSubKey ) )
           fErr = TRUE;

    wsprintf( aSubKey, "%s\\Interface\\%s", aPrefix, aInterIDWinPeer );
    if( ERROR_SUCCESS != SHDeleteKey( bForAllUsers ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER, aSubKey ) )
           fErr = TRUE;

    wsprintf( aSubKey, "%s\\Interface\\%s", aPrefix, aInterIDDispInt );
    if( ERROR_SUCCESS != SHDeleteKey( bForAllUsers ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER, aSubKey ) )
           fErr = TRUE;

    wsprintf( aSubKey, "%s\\Interface\\%s", aPrefix, aInterIDActApprove );
    if( ERROR_SUCCESS != SHDeleteKey( bForAllUsers ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER, aSubKey ) )
           fErr = TRUE;

    return !fErr;
}

/////////////////////////////////////////////////////////////////////////////
// DllRegisterServerDoc - Adds entries to the system registry

#define SUPPORTED_MSEXT_NUM 7
const char* aMSFileExt[] = { ".dot", ".doc", ".xlt", ".xls", ".pot", ".ppt", ".pps" };
const char* aMSMimeType[] = { "application/msword",
                          "application/msword",
                          "application/msexcell",
                          "application/msexcell",
                          "application/mspowerpoint",
                          "application/mspowerpoint",
                          "application/mspowerpoint" };
const int nForMSModes[] = { 1, 1, 2, 2, 4, 4, 4 };

STDAPI DllUnregisterServerDoc( int nMode, BOOL bForAllUsers );
STDAPI DllRegisterServerDoc( int nMode, BOOL bForAllUsers )
{
    BOOL aResult = TRUE;

    HKEY        hkey = NULL;
    HKEY        hkey1 = NULL;
    char        aSubKey[513];
    int         ind;
    const char* aPrefix = aLocalPrefix; // bForAllUsers ? "" : aLocalPrefix;

    // In case SO7 is installed for this user he can have local registry entries that will prevent him from
    // using SO8 ActiveX control. The fix is just to clean up the local entries related to ActiveX control.
    // Unfortunately it can be done only for the user who installs the office.
    if ( bForAllUsers )
        DllUnregisterServerDoc( nMode, sal_False );

    for( ind = 0; ind < SUPPORTED_MSEXT_NUM && aResult; ind++ )
    {
        if( nForMSModes[ind] & nMode )
        {
               wsprintf( aSubKey, "%sMIME\\DataBase\\Content Type\\%s", aPrefix, aMSMimeType[ind] );
               if ( ERROR_SUCCESS != RegCreateKey(bForAllUsers ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER, aSubKey, &hkey)
               || ERROR_SUCCESS != RegSetValueEx(hkey, "Extension", 0, REG_SZ,
                   (const BYTE *)aMSFileExt[ind], strlen( aMSFileExt[ind] ) )
               || ERROR_SUCCESS != RegSetValueEx(hkey, "CLSID", 0, REG_SZ,
                   (const BYTE *)aClassID, strlen(aClassID)) )
                       aResult = FALSE;

               if( hkey )
                   RegCloseKey(hkey),hkey= NULL;

               wsprintf( aSubKey, "%s%s", aPrefix, aMSFileExt[ind] );
               if ( ERROR_SUCCESS != RegCreateKey(bForAllUsers ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER, aSubKey, &hkey)
               || ERROR_SUCCESS != RegSetValueEx(hkey, "Content Type", 0, REG_SZ,
                   (const BYTE *)aMSMimeType[ind], strlen( aMSMimeType[ind] ) ) )
                       aResult = FALSE;

               if( hkey )
                   RegCloseKey(hkey),hkey= NULL;
        }
    }

    wsprintf( aSubKey, "%sCLSID\\%s", aPrefix, aClassID );
    if ( aResult && ERROR_SUCCESS == RegCreateKey( bForAllUsers ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER, aSubKey, &hkey )
      && createKey( hkey, "EnableFullPage" ) )
    {
           for( ind = 0; ind < SUPPORTED_MSEXT_NUM; ind++ )
           {
            if( nForMSModes[ind] & nMode )
            {
                   wsprintf( aSubKey, "EnableFullPage\\%s", aMSFileExt[ind] );
                   if ( ERROR_SUCCESS != RegCreateKey( hkey, aSubKey, &hkey1 ) )
                       aResult = FALSE;

                   if ( hkey1 )
                       RegCloseKey(hkey1),hkey1= NULL;
            }
           }
    }
    else
        aResult = FALSE;

    if ( hkey )
        RegCloseKey(hkey),hkey= NULL;

    return aResult;
}



/////////////////////////////////////////////////////////////////////////////
// DllUnregisterServerDoc - Removes entries from the system registry

STDAPI DllUnregisterServerDoc( int nMode, BOOL bForAllUsers )
{
    HKEY        hkey = NULL;
    BOOL        fErr = FALSE;
    char        aSubKey[513];
    const char* aPrefix = aLocalPrefix; // bForAllUsers ? "" : aLocalPrefix;

      for( int ind = 0; ind < SUPPORTED_MSEXT_NUM; ind++ )
       {
        if( nForMSModes[ind] & nMode )
        {
            DWORD nSubKeys = 0, nValues = 0;

               wsprintf( aSubKey, "%sMIME\\DataBase\\Content Type\\%s", aPrefix, aMSMimeType[ind] );
               if ( ERROR_SUCCESS != RegCreateKey(bForAllUsers ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER, aSubKey, &hkey) )
                fErr = TRUE;
            else
            {
                   if ( ERROR_SUCCESS != RegDeleteValue( hkey, "Extension" ) )
                    fErr = TRUE;

                   if ( ERROR_SUCCESS != RegDeleteValue( hkey, "CLSID" ) )
                    fErr = TRUE;

                if ( ERROR_SUCCESS != RegQueryInfoKey(  hkey, NULL, NULL, NULL,
                                                        &nSubKeys, NULL, NULL,
                                                        &nValues, NULL, NULL, NULL, NULL ) )
                {
                    RegCloseKey( hkey ), hkey = NULL;
                    fErr = TRUE;
                }
                else
                {
                    RegCloseKey( hkey ), hkey = NULL;
                    if ( !nSubKeys && !nValues )
                        SHDeleteKey( bForAllUsers ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER, aSubKey );
                }
            }

               wsprintf( aSubKey, "%s%s", aPrefix, aMSFileExt[ind] );
               if ( ERROR_SUCCESS != RegCreateKey(bForAllUsers ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER, aSubKey, &hkey) )
                fErr = TRUE;
            else
            {
                   if ( ERROR_SUCCESS != RegDeleteValue( hkey, "Content Type" ) )
                    fErr = TRUE;

                if ( ERROR_SUCCESS != RegQueryInfoKey(  hkey, NULL, NULL, NULL,
                                                        &nSubKeys, NULL, NULL,
                                                        &nValues, NULL, NULL, NULL, NULL ) )
                {
                    RegCloseKey( hkey ), hkey = NULL;
                    fErr = TRUE;
                }
                else
                {
                    RegCloseKey( hkey ), hkey = NULL;
                    if ( !nSubKeys && !nValues )
                        SHDeleteKey( bForAllUsers ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER, aSubKey );
                }
            }
        }
       }

    return !fErr;
}

STDAPI DllRegisterServer( void )
{
    char pActiveXPath[1019];
    HRESULT aResult = E_FAIL;

    HMODULE aCurModule = GetModuleHandleA( "so_activex.dll" );
    if( aCurModule && GetModuleFileNameA( aCurModule, pActiveXPath, 1019 ) )
    {
        aResult = DllRegisterServerNative( 31, TRUE, pActiveXPath );
        if( SUCCEEDED( aResult ) )
            aResult = DllRegisterServerDoc( 31, TRUE );
        else
        {
            aResult = DllRegisterServerNative( 31, FALSE, pActiveXPath );
            if( SUCCEEDED( aResult ) )
                aResult = DllRegisterServerDoc( 31, FALSE );
        }
    }

    return aResult;
}

STDAPI DllUnregisterServer( void )
{
    DllUnregisterServerDoc( 63, FALSE );
    DllUnregisterServerNative( 63, FALSE );
    DllUnregisterServerDoc( 63, TRUE );
    return DllUnregisterServerNative( 63, TRUE );
}