]> git.saurik.com Git - apple/mdnsresponder.git/blob - Clients/ExplorerPlugin/ExplorerPlugin.cpp
mDNSResponder-107.tar.gz
[apple/mdnsresponder.git] / Clients / ExplorerPlugin / ExplorerPlugin.cpp
1 /*
2 * Copyright (c) 2003-2004 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
11 * file.
12 *
13 * The Original Code and all software distributed under the License are
14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 * Please see the License for the specific language governing rights and
19 * limitations under the License.
20 *
21 * @APPLE_LICENSE_HEADER_END@
22
23 Change History (most recent first):
24
25 $Log: ExplorerPlugin.cpp,v $
26 Revision 1.7 2005/02/23 02:00:45 shersche
27 <rdar://problem/4014479> Delete all the registry entries when component is unregistered
28
29 Revision 1.6 2005/01/25 17:56:45 shersche
30 <rdar://problem/3911084> Load resource DLLs, get icons and bitmaps from resource DLLs
31 Bug #: 3911084
32
33 Revision 1.5 2004/09/15 10:33:54 shersche
34 <rdar://problem/3721611> Install XP toolbar button (8 bit mask) if running on XP platform, otherwise install 1 bit mask toolbar button
35 Bug #: 3721611
36
37 Revision 1.4 2004/07/13 21:24:21 rpantos
38 Fix for <rdar://problem/3701120>.
39
40 Revision 1.3 2004/06/26 14:12:07 shersche
41 Register the toolbar button
42
43 Revision 1.2 2004/06/24 20:09:39 shersche
44 Change text
45 Submitted by: herscher
46
47 Revision 1.1 2004/06/18 04:34:59 rpantos
48 Move to Clients from mDNSWindows
49
50 Revision 1.1 2004/01/30 03:01:56 bradley
51 Explorer Plugin to browse for DNS-SD advertised Web and FTP servers from within Internet Explorer.
52
53 */
54
55 #include "StdAfx.h"
56
57 // The following 2 includes have to be in this order and INITGUID must be defined here, before including the file
58 // that specifies the GUID(s), and nowhere else. The reason for this is that initguid.h doesn't provide separate
59 // define and declare macros for GUIDs so you have to #define INITGUID in the single file where you want to define
60 // your GUID then in all the other files that just need the GUID declared, INITGUID must not be defined.
61
62 #define INITGUID
63 #include <initguid.h>
64 #include "ExplorerPlugin.h"
65
66 #include <comcat.h>
67 #include <Shlwapi.h>
68
69 #include "CommonServices.h"
70 #include "DebugServices.h"
71
72 #include "ClassFactory.h"
73 #include "Resource.h"
74
75 #include "loclibrary.h"
76
77 // MFC Debugging
78
79 #ifdef _DEBUG
80 #define new DEBUG_NEW
81 #undef THIS_FILE
82 static char THIS_FILE[] = __FILE__;
83 #endif
84
85 #if 0
86 #pragma mark == Prototypes ==
87 #endif
88
89 //===========================================================================================================================
90 // Prototypes
91 //===========================================================================================================================
92
93 // DLL Exports
94
95 extern "C" BOOL WINAPI DllMain( HINSTANCE inInstance, DWORD inReason, LPVOID inReserved );
96
97 // MFC Support
98
99 DEBUG_LOCAL OSStatus MFCDLLProcessAttach( HINSTANCE inInstance );
100 DEBUG_LOCAL void MFCDLLProcessDetach( HINSTANCE inInstance );
101 DEBUG_LOCAL void MFCDLLThreadDetach( HINSTANCE inInstance );
102
103 // Utilities
104
105 DEBUG_LOCAL OSStatus RegisterServer( HINSTANCE inInstance, CLSID inCLSID, LPCTSTR inName );
106 DEBUG_LOCAL OSStatus RegisterCOMCategory( CLSID inCLSID, CATID inCategoryID, BOOL inRegister );
107 DEBUG_LOCAL OSStatus UnregisterServer( CLSID inCLSID );
108 DEBUG_LOCAL OSStatus MyRegDeleteKey( HKEY hKeyRoot, LPTSTR lpSubKey );
109
110 // Stash away pointers to our resource DLLs
111
112 static HINSTANCE g_nonLocalizedResources = NULL;
113 static CString g_nonLocalizedResourcesName;
114 static HINSTANCE g_localizedResources = NULL;
115
116 HINSTANCE
117 GetNonLocalizedResources()
118 {
119 return g_nonLocalizedResources;
120 }
121
122 HINSTANCE
123 GetLocalizedResources()
124 {
125 return g_localizedResources;
126 }
127
128 #if 0
129 #pragma mark == Globals ==
130 #endif
131
132 //===========================================================================================================================
133 // Globals
134 //===========================================================================================================================
135
136 HINSTANCE gInstance = NULL;
137 int gDLLRefCount = 0;
138 CWinApp gApp;
139
140 #if 0
141 #pragma mark -
142 #pragma mark == DLL Exports ==
143 #endif
144
145 //===========================================================================================================================
146 // DllMain
147 //===========================================================================================================================
148
149 BOOL WINAPI DllMain( HINSTANCE inInstance, DWORD inReason, LPVOID inReserved )
150 {
151 BOOL ok;
152 OSStatus err;
153
154 DEBUG_UNUSED( inReserved );
155
156 ok = TRUE;
157 switch( inReason )
158 {
159 case DLL_PROCESS_ATTACH:
160 gInstance = inInstance;
161 debug_initialize( kDebugOutputTypeWindowsEventLog, "DNSServices Bar", inInstance );
162 debug_set_property( kDebugPropertyTagPrintLevel, kDebugLevelTrace );
163 dlog( kDebugLevelTrace, "\nDllMain: process attach\n" );
164
165 err = MFCDLLProcessAttach( inInstance );
166 ok = ( err == kNoErr );
167 require_noerr( err, exit );
168 break;
169
170 case DLL_PROCESS_DETACH:
171 dlog( kDebugLevelTrace, "DllMain: process detach\n" );
172 MFCDLLProcessDetach( inInstance );
173 break;
174
175 case DLL_THREAD_ATTACH:
176 dlog( kDebugLevelTrace, "DllMain: thread attach\n" );
177 break;
178
179 case DLL_THREAD_DETACH:
180 dlog( kDebugLevelTrace, "DllMain: thread detach\n" );
181 MFCDLLThreadDetach( inInstance );
182 break;
183
184 default:
185 dlog( kDebugLevelTrace, "DllMain: unknown reason code (%d)\n",inReason );
186 break;
187 }
188
189 exit:
190 return( ok );
191 }
192
193 //===========================================================================================================================
194 // DllCanUnloadNow
195 //===========================================================================================================================
196
197 STDAPI DllCanUnloadNow( void )
198 {
199 dlog( kDebugLevelTrace, "DllCanUnloadNow (refCount=%d)\n", gDLLRefCount );
200
201 return( gDLLRefCount == 0 );
202 }
203
204 //===========================================================================================================================
205 // DllGetClassObject
206 //===========================================================================================================================
207
208 STDAPI DllGetClassObject( REFCLSID inCLSID, REFIID inIID, LPVOID *outResult )
209 {
210 HRESULT err;
211 BOOL ok;
212 ClassFactory * factory;
213
214 dlog( kDebugLevelTrace, "DllGetClassObject\n" );
215
216 *outResult = NULL;
217
218 // Check if the class ID is supported.
219
220 ok = IsEqualCLSID( inCLSID, CLSID_ExplorerBar );
221 require_action_quiet( ok, exit, err = CLASS_E_CLASSNOTAVAILABLE );
222
223 // Create the ClassFactory object.
224
225 factory = NULL;
226 try
227 {
228 factory = new ClassFactory( inCLSID );
229 }
230 catch( ... )
231 {
232 // Do not let exception escape.
233 }
234 require_action( factory, exit, err = E_OUTOFMEMORY );
235
236 // Query for the specified interface. Release the factory since QueryInterface retains it.
237
238 err = factory->QueryInterface( inIID, outResult );
239 factory->Release();
240
241 exit:
242 return( err );
243 }
244
245 //===========================================================================================================================
246 // DllRegisterServer
247 //===========================================================================================================================
248
249 STDAPI DllRegisterServer( void )
250 {
251 HRESULT err;
252 BOOL ok;
253 CString s;
254
255 dlog( kDebugLevelTrace, "DllRegisterServer\n" );
256
257 ok = s.LoadString( IDS_NAME );
258 require_action( ok, exit, err = E_UNEXPECTED );
259
260 err = RegisterServer( gInstance, CLSID_ExplorerBar, s );
261 require_noerr( err, exit );
262
263 err = RegisterCOMCategory( CLSID_ExplorerBar, CATID_InfoBand, TRUE );
264 require_noerr( err, exit );
265
266 exit:
267 return( err );
268 }
269
270 //===========================================================================================================================
271 // DllUnregisterServer
272 //===========================================================================================================================
273
274 STDAPI DllUnregisterServer( void )
275 {
276 HRESULT err;
277
278 dlog( kDebugLevelTrace, "DllUnregisterServer\n" );
279
280 err = RegisterCOMCategory( CLSID_ExplorerBar, CATID_InfoBand, FALSE );
281 require_noerr( err, exit );
282
283 err = UnregisterServer( CLSID_ExplorerBar );
284 require_noerr( err, exit );
285
286 exit:
287 return( err );
288 }
289
290 #if 0
291 #pragma mark -
292 #pragma mark == MFC Support ==
293 #endif
294
295 //===========================================================================================================================
296 // MFCDLLProcessAttach
297 //===========================================================================================================================
298
299 DEBUG_LOCAL OSStatus MFCDLLProcessAttach( HINSTANCE inInstance )
300 {
301 wchar_t resource[MAX_PATH];
302 OSStatus err;
303 _AFX_THREAD_STATE * threadState;
304 AFX_MODULE_STATE * previousModuleState;
305 BOOL ok;
306 int res;
307 CWinApp * app;
308
309 app = NULL;
310
311 // Simulate what is done in dllmodul.cpp.
312
313 threadState = AfxGetThreadState();
314 check( threadState );
315 previousModuleState = threadState->m_pPrevModuleState;
316
317 ok = AfxWinInit( inInstance, NULL, TEXT( "" ), 0 );
318 require_action( ok, exit, err = kUnknownErr );
319
320 app = AfxGetApp();
321 require_action( ok, exit, err = kNotInitializedErr );
322
323 // Before we load the resources, let's load the error string
324
325 // errorMessage.LoadString( IDS_REINSTALL );
326 // errorCaption.LoadString( IDS_REINSTALL_CAPTION );
327
328 // Load Resources
329
330 res = PathForResource( inInstance, L"ExplorerPluginResources.dll", resource, MAX_PATH );
331
332 err = translate_errno( res != 0, kUnknownErr, kUnknownErr );
333 require_noerr( err, exit );
334
335 g_nonLocalizedResources = LoadLibrary( resource );
336 translate_errno( g_nonLocalizedResources, GetLastError(), kUnknownErr );
337 require_noerr( err, exit );
338
339 g_nonLocalizedResourcesName = resource;
340
341 res = PathForResource( inInstance, L"ExplorerPluginLocalized.dll", resource, MAX_PATH );
342 err = translate_errno( res != 0, kUnknownErr, kUnknownErr );
343 require_noerr( err, exit );
344
345 g_localizedResources = LoadLibrary( resource );
346 translate_errno( g_localizedResources, GetLastError(), kUnknownErr );
347 require_noerr( err, exit );
348
349 AfxSetResourceHandle( g_localizedResources );
350
351 ok = app->InitInstance();
352 require_action( ok, exit, err = kUnknownErr );
353
354 threadState->m_pPrevModuleState = previousModuleState;
355 threadState = NULL;
356 AfxInitLocalData( inInstance );
357 err = kNoErr;
358
359 exit:
360 if( err )
361 {
362 if( app )
363 {
364 app->ExitInstance();
365 }
366 AfxWinTerm();
367 }
368 if( threadState )
369 {
370 threadState->m_pPrevModuleState = previousModuleState;
371 }
372 return( err );
373 }
374
375 //===========================================================================================================================
376 // MFCDLLProcessDetach
377 //===========================================================================================================================
378
379 DEBUG_LOCAL void MFCDLLProcessDetach( HINSTANCE inInstance )
380 {
381 CWinApp * app;
382
383 // Simulate what is done in dllmodul.cpp.
384
385 app = AfxGetApp();
386 if( app )
387 {
388 app->ExitInstance();
389 }
390
391 #if( DEBUG )
392 if( AfxGetModuleThreadState()->m_nTempMapLock != 0 )
393 {
394 dlog( kDebugLevelWarning, "Warning: Temp map lock count non-zero (%ld).\n", AfxGetModuleThreadState()->m_nTempMapLock );
395 }
396 #endif
397
398 AfxLockTempMaps();
399 AfxUnlockTempMaps( -1 );
400
401 // Terminate the library before destructors are called.
402
403 AfxWinTerm();
404 AfxTermLocalData( inInstance, TRUE );
405 }
406
407 //===========================================================================================================================
408 // MFCDLLFinalize
409 //===========================================================================================================================
410
411 DEBUG_LOCAL void MFCDLLThreadDetach( HINSTANCE inInstance )
412 {
413 // Simulate what is done in dllmodul.cpp.
414
415 #if( DEBUG )
416 if( AfxGetModuleThreadState()->m_nTempMapLock != 0 )
417 {
418 dlog( kDebugLevelWarning, "Warning: Temp map lock count non-zero (%ld).\n", AfxGetModuleThreadState()->m_nTempMapLock );
419 }
420 #endif
421
422 AfxLockTempMaps();
423 AfxUnlockTempMaps( -1 );
424 AfxTermThread( inInstance );
425 }
426
427 #if 0
428 #pragma mark -
429 #pragma mark == Utilities ==
430 #endif
431
432 //===========================================================================================================================
433 // RegisterServer
434 //===========================================================================================================================
435
436 DEBUG_LOCAL OSStatus RegisterServer( HINSTANCE inInstance, CLSID inCLSID, LPCTSTR inName )
437 {
438 typedef struct RegistryBuilder RegistryBuilder;
439 struct RegistryBuilder
440 {
441 HKEY rootKey;
442 LPCTSTR subKey;
443 LPCTSTR valueName;
444 LPCTSTR data;
445 };
446
447 OSStatus err;
448 LPWSTR clsidWideString;
449 TCHAR clsidString[ 64 ];
450 DWORD nChars;
451 size_t n;
452 size_t i;
453 HKEY key;
454 TCHAR keyName[ MAX_PATH ];
455 TCHAR moduleName[ MAX_PATH ] = TEXT( "" );
456 TCHAR data[ MAX_PATH ];
457 RegistryBuilder entries[] =
458 {
459 { HKEY_CLASSES_ROOT, TEXT( "CLSID\\%s" ), NULL, inName },
460 { HKEY_CLASSES_ROOT, TEXT( "CLSID\\%s\\InprocServer32" ), NULL, moduleName },
461 { HKEY_CLASSES_ROOT, TEXT( "CLSID\\%s\\InprocServer32" ), TEXT( "ThreadingModel" ), TEXT( "Apartment" ) }
462 };
463 DWORD size;
464 OSVERSIONINFO versionInfo;
465
466 // Convert the CLSID to a string based on the encoding of this code (ANSI or Unicode).
467
468 err = StringFromIID( inCLSID, &clsidWideString );
469 require_noerr( err, exit );
470 require_action( clsidWideString, exit, err = kNoMemoryErr );
471
472 #ifdef UNICODE
473 lstrcpyn( clsidString, clsidWideString, sizeof_array( clsidString ) );
474 CoTaskMemFree( clsidWideString );
475 #else
476 nChars = WideCharToMultiByte( CP_ACP, 0, clsidWideString, -1, clsidString, sizeof_array( clsidString ), NULL, NULL );
477 err = translate_errno( nChars > 0, (OSStatus) GetLastError(), kUnknownErr );
478 CoTaskMemFree( clsidWideString );
479 require_noerr( err, exit );
480 #endif
481
482 // Register the CLSID entries.
483
484 nChars = GetModuleFileName( inInstance, moduleName, sizeof_array( moduleName ) );
485 err = translate_errno( nChars > 0, (OSStatus) GetLastError(), kUnknownErr );
486 require_noerr( err, exit );
487
488 n = sizeof_array( entries );
489 for( i = 0; i < n; ++i )
490 {
491 wsprintf( keyName, entries[ i ].subKey, clsidString );
492 err = RegCreateKeyEx( entries[ i ].rootKey, keyName, 0, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &key, NULL );
493 require_noerr( err, exit );
494
495 size = (DWORD)( ( lstrlen( entries[ i ].data ) + 1 ) * sizeof( TCHAR ) );
496 err = RegSetValueEx( key, entries[ i ].valueName, 0, REG_SZ, (LPBYTE) entries[ i ].data, size );
497 RegCloseKey( key );
498 require_noerr( err, exit );
499 }
500
501 // If running on NT, register the extension as approved.
502
503 versionInfo.dwOSVersionInfoSize = sizeof( versionInfo );
504 GetVersionEx( &versionInfo );
505 if( versionInfo.dwPlatformId == VER_PLATFORM_WIN32_NT )
506 {
507 lstrcpyn( keyName, TEXT( "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Shell Extensions\\Approved" ), sizeof_array( keyName ) );
508 err = RegCreateKeyEx( HKEY_LOCAL_MACHINE, keyName, 0, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &key, NULL );
509 require_noerr( err, exit );
510
511 lstrcpyn( data, inName, sizeof_array( data ) );
512 size = (DWORD)( ( lstrlen( data ) + 1 ) * sizeof( TCHAR ) );
513 err = RegSetValueEx( key, clsidString, 0, REG_SZ, (LPBYTE) data, size );
514 RegCloseKey( key );
515 }
516
517 // register toolbar button
518 lstrcpyn( keyName, TEXT( "SOFTWARE\\Microsoft\\Internet Explorer\\Extensions\\{7F9DB11C-E358-4ca6-A83D-ACC663939424}"), sizeof_array( keyName ) );
519 err = RegCreateKeyEx( HKEY_LOCAL_MACHINE, keyName, 0, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &key, NULL );
520 require_noerr( err, exit );
521
522 lstrcpyn( data, L"Yes", sizeof_array( data ) );
523 size = (DWORD)( ( lstrlen( data ) + 1 ) * sizeof( TCHAR ) );
524 RegSetValueEx( key, L"Default Visible", 0, REG_SZ, (LPBYTE) data, size );
525
526 lstrcpyn( data, inName, sizeof_array( data ) );
527 size = (DWORD)( ( lstrlen( data ) + 1 ) * sizeof( TCHAR ) );
528 RegSetValueEx( key, L"ButtonText", 0, REG_SZ, (LPBYTE) data, size );
529
530 lstrcpyn( data, L"{E0DD6CAB-2D10-11D2-8F1A-0000F87ABD16}", sizeof_array( data ) );
531 size = (DWORD)( ( lstrlen( data ) + 1 ) * sizeof( TCHAR ) );
532 RegSetValueEx( key, L"CLSID", 0, REG_SZ, (LPBYTE) data, size );
533
534 lstrcpyn( data, clsidString, sizeof_array( data ) );
535 size = (DWORD)( ( lstrlen( data ) + 1 ) * sizeof( TCHAR ) );
536 RegSetValueEx( key, L"BandCLSID", 0, REG_SZ, (LPBYTE) data, size );
537
538 // check if we're running XP or later
539 if ( ( versionInfo.dwPlatformId == VER_PLATFORM_WIN32_NT ) &&
540 ( versionInfo.dwMajorVersion == 5 ) &&
541 ( versionInfo.dwMinorVersion >= 1 ) )
542 {
543 wsprintf( data, L"%s,%d", (LPCTSTR) g_nonLocalizedResourcesName, IDI_BUTTON_XP );
544 size = (DWORD)( ( lstrlen( data ) + 1 ) * sizeof( TCHAR ) );
545 RegSetValueEx( key, L"Icon", 0, REG_SZ, (LPBYTE) data, size);
546
547 wsprintf( data, L"%s,%d", (LPCTSTR) g_nonLocalizedResourcesName, IDI_BUTTON_XP );
548 size = (DWORD)( ( lstrlen( data ) + 1 ) * sizeof( TCHAR ) );
549 RegSetValueEx( key, L"HotIcon", 0, REG_SZ, (LPBYTE) data, size);
550 }
551 else
552 {
553 wsprintf( data, L"%s,%d", (LPCTSTR) g_nonLocalizedResourcesName, IDI_BUTTON_2K );
554 size = (DWORD)( ( lstrlen( data ) + 1 ) * sizeof( TCHAR ) );
555 RegSetValueEx( key, L"Icon", 0, REG_SZ, (LPBYTE) data, size);
556
557 wsprintf( data, L"%s,%d", (LPCTSTR) g_nonLocalizedResourcesName, IDI_BUTTON_2K );
558 size = (DWORD)( ( lstrlen( data ) + 1 ) * sizeof( TCHAR ) );
559 RegSetValueEx( key, L"HotIcon", 0, REG_SZ, (LPBYTE) data, size);
560 }
561
562 RegCloseKey( key );
563
564 exit:
565 return( err );
566 }
567
568 //===========================================================================================================================
569 // RegisterCOMCategory
570 //===========================================================================================================================
571
572 DEBUG_LOCAL OSStatus RegisterCOMCategory( CLSID inCLSID, CATID inCategoryID, BOOL inRegister )
573 {
574 HRESULT err;
575 ICatRegister * cat;
576
577 err = CoInitialize( NULL );
578 require( SUCCEEDED( err ), exit );
579
580 err = CoCreateInstance( CLSID_StdComponentCategoriesMgr, NULL, CLSCTX_INPROC_SERVER, IID_ICatRegister, (LPVOID *) &cat );
581 check( SUCCEEDED( err ) );
582 if( SUCCEEDED( err ) )
583 {
584 if( inRegister )
585 {
586 err = cat->RegisterClassImplCategories( inCLSID, 1, &inCategoryID );
587 check_noerr( err );
588 }
589 else
590 {
591 err = cat->UnRegisterClassImplCategories( inCLSID, 1, &inCategoryID );
592 check_noerr( err );
593 }
594 cat->Release();
595 }
596 CoUninitialize();
597
598 exit:
599 return( err );
600 }
601
602
603 //===========================================================================================================================
604 // UnregisterServer
605 //===========================================================================================================================
606
607 DEBUG_LOCAL OSStatus UnregisterServer( CLSID inCLSID )
608 {
609 OSStatus err = 0;
610 LPWSTR clsidWideString;
611 TCHAR clsidString[ 64 ];
612 HKEY key;
613 TCHAR keyName[ MAX_PATH * 2 ];
614 OSVERSIONINFO versionInfo;
615
616 // Convert the CLSID to a string based on the encoding of this code (ANSI or Unicode).
617
618 err = StringFromIID( inCLSID, &clsidWideString );
619 require_noerr( err, exit );
620 require_action( clsidWideString, exit, err = kNoMemoryErr );
621
622 #ifdef UNICODE
623 lstrcpyn( clsidString, clsidWideString, sizeof_array( clsidString ) );
624 CoTaskMemFree( clsidWideString );
625 #else
626 nChars = WideCharToMultiByte( CP_ACP, 0, clsidWideString, -1, clsidString, sizeof_array( clsidString ), NULL, NULL );
627 err = translate_errno( nChars > 0, (OSStatus) GetLastError(), kUnknownErr );
628 CoTaskMemFree( clsidWideString );
629 require_noerr( err, exit );
630 #endif
631
632 wsprintf( keyName, L"CLSID\\%s", clsidString );
633 MyRegDeleteKey( HKEY_CLASSES_ROOT, keyName );
634
635 // If running on NT, de-register the extension as approved.
636
637 versionInfo.dwOSVersionInfoSize = sizeof( versionInfo );
638 GetVersionEx( &versionInfo );
639 if( versionInfo.dwPlatformId == VER_PLATFORM_WIN32_NT )
640 {
641 lstrcpyn( keyName, TEXT( "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Shell Extensions\\Approved" ), sizeof_array( keyName ) );
642 err = RegCreateKeyEx( HKEY_LOCAL_MACHINE, keyName, 0, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &key, NULL );
643 require_noerr( err, exit );
644
645 RegDeleteValue( key, clsidString );
646
647 err = RegCloseKey( key );
648 require_noerr( err, exit );
649 }
650
651 // de-register toolbar button
652
653 lstrcpyn( keyName, TEXT( "SOFTWARE\\Microsoft\\Internet Explorer\\Extensions\\{7F9DB11C-E358-4ca6-A83D-ACC663939424}"), sizeof_array( keyName ) );
654 MyRegDeleteKey( HKEY_LOCAL_MACHINE, keyName );
655
656 exit:
657 return( err );
658 }
659
660
661
662 //===========================================================================================================================
663 // MyRegDeleteKey
664 //===========================================================================================================================
665
666 DEBUG_LOCAL OSStatus MyRegDeleteKey( HKEY hKeyRoot, LPTSTR lpSubKey )
667 {
668 LPTSTR lpEnd;
669 OSStatus err;
670 DWORD dwSize;
671 TCHAR szName[MAX_PATH];
672 HKEY hKey;
673 FILETIME ftWrite;
674
675 // First, see if we can delete the key without having to recurse.
676
677 err = RegDeleteKey( hKeyRoot, lpSubKey );
678
679 if ( !err )
680 {
681 goto exit;
682 }
683
684 err = RegOpenKeyEx( hKeyRoot, lpSubKey, 0, KEY_READ, &hKey );
685 require_noerr( err, exit );
686
687 // Check for an ending slash and add one if it is missing.
688
689 lpEnd = lpSubKey + lstrlen(lpSubKey);
690
691 if ( *( lpEnd - 1 ) != TEXT( '\\' ) )
692 {
693 *lpEnd = TEXT('\\');
694 lpEnd++;
695 *lpEnd = TEXT('\0');
696 }
697
698 // Enumerate the keys
699
700 dwSize = MAX_PATH;
701 err = RegEnumKeyEx(hKey, 0, szName, &dwSize, NULL, NULL, NULL, &ftWrite);
702
703 if ( !err )
704 {
705 do
706 {
707 lstrcpy (lpEnd, szName);
708
709 if ( !MyRegDeleteKey( hKeyRoot, lpSubKey ) )
710 {
711 break;
712 }
713
714 dwSize = MAX_PATH;
715
716 err = RegEnumKeyEx( hKey, 0, szName, &dwSize, NULL, NULL, NULL, &ftWrite );
717
718 }
719 while ( !err );
720 }
721
722 lpEnd--;
723 *lpEnd = TEXT('\0');
724
725 RegCloseKey( hKey );
726
727 // Try again to delete the key.
728
729 err = RegDeleteKey(hKeyRoot, lpSubKey);
730 require_noerr( err, exit );
731
732 exit:
733
734 return err;
735 }