]> git.saurik.com Git - apple/mdnsresponder.git/blob - Clients/ExplorerPlugin/ExplorerPlugin.cpp
mDNSResponder-161.1.tar.gz
[apple/mdnsresponder.git] / Clients / ExplorerPlugin / ExplorerPlugin.cpp
1 /* -*- Mode: C; tab-width: 4 -*-
2 *
3 * Copyright (c) 2003-2004 Apple Computer, Inc. All rights reserved.
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16
17 Change History (most recent first):
18
19 $Log: ExplorerPlugin.cpp,v $
20 Revision 1.9 2006/08/14 23:24:00 cheshire
21 Re-licensed mDNSResponder daemon source code under Apache License, Version 2.0
22
23 Revision 1.8 2005/06/30 18:01:54 shersche
24 <rdar://problem/4130635> Cause IE to rebuild cache so we don't have to reboot following an install.
25
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 // This is the class GUID for an undocumented hook into IE that will allow us to register
129 // and have IE notice our new ExplorerBar without rebooting.
130 // {8C7461EF-2B13-11d2-BE35-3078302C2030}
131
132 DEFINE_GUID(CLSID_CompCatCacheDaemon,
133 0x8C7461EF, 0x2b13, 0x11d2, 0xbe, 0x35, 0x30, 0x78, 0x30, 0x2c, 0x20, 0x30);
134
135
136 #if 0
137 #pragma mark == Globals ==
138 #endif
139
140 //===========================================================================================================================
141 // Globals
142 //===========================================================================================================================
143
144 HINSTANCE gInstance = NULL;
145 int gDLLRefCount = 0;
146 CWinApp gApp;
147
148 #if 0
149 #pragma mark -
150 #pragma mark == DLL Exports ==
151 #endif
152
153 //===========================================================================================================================
154 // DllMain
155 //===========================================================================================================================
156
157 BOOL WINAPI DllMain( HINSTANCE inInstance, DWORD inReason, LPVOID inReserved )
158 {
159 BOOL ok;
160 OSStatus err;
161
162 DEBUG_UNUSED( inReserved );
163
164 ok = TRUE;
165 switch( inReason )
166 {
167 case DLL_PROCESS_ATTACH:
168 gInstance = inInstance;
169 debug_initialize( kDebugOutputTypeWindowsEventLog, "DNSServices Bar", inInstance );
170 debug_set_property( kDebugPropertyTagPrintLevel, kDebugLevelTrace );
171 dlog( kDebugLevelTrace, "\nDllMain: process attach\n" );
172
173 err = MFCDLLProcessAttach( inInstance );
174 ok = ( err == kNoErr );
175 require_noerr( err, exit );
176 break;
177
178 case DLL_PROCESS_DETACH:
179 dlog( kDebugLevelTrace, "DllMain: process detach\n" );
180 MFCDLLProcessDetach( inInstance );
181 break;
182
183 case DLL_THREAD_ATTACH:
184 dlog( kDebugLevelTrace, "DllMain: thread attach\n" );
185 break;
186
187 case DLL_THREAD_DETACH:
188 dlog( kDebugLevelTrace, "DllMain: thread detach\n" );
189 MFCDLLThreadDetach( inInstance );
190 break;
191
192 default:
193 dlog( kDebugLevelTrace, "DllMain: unknown reason code (%d)\n",inReason );
194 break;
195 }
196
197 exit:
198 return( ok );
199 }
200
201 //===========================================================================================================================
202 // DllCanUnloadNow
203 //===========================================================================================================================
204
205 STDAPI DllCanUnloadNow( void )
206 {
207 dlog( kDebugLevelTrace, "DllCanUnloadNow (refCount=%d)\n", gDLLRefCount );
208
209 return( gDLLRefCount == 0 );
210 }
211
212 //===========================================================================================================================
213 // DllGetClassObject
214 //===========================================================================================================================
215
216 STDAPI DllGetClassObject( REFCLSID inCLSID, REFIID inIID, LPVOID *outResult )
217 {
218 HRESULT err;
219 BOOL ok;
220 ClassFactory * factory;
221
222 dlog( kDebugLevelTrace, "DllGetClassObject\n" );
223
224 *outResult = NULL;
225
226 // Check if the class ID is supported.
227
228 ok = IsEqualCLSID( inCLSID, CLSID_ExplorerBar );
229 require_action_quiet( ok, exit, err = CLASS_E_CLASSNOTAVAILABLE );
230
231 // Create the ClassFactory object.
232
233 factory = NULL;
234 try
235 {
236 factory = new ClassFactory( inCLSID );
237 }
238 catch( ... )
239 {
240 // Do not let exception escape.
241 }
242 require_action( factory, exit, err = E_OUTOFMEMORY );
243
244 // Query for the specified interface. Release the factory since QueryInterface retains it.
245
246 err = factory->QueryInterface( inIID, outResult );
247 factory->Release();
248
249 exit:
250 return( err );
251 }
252
253 //===========================================================================================================================
254 // DllRegisterServer
255 //===========================================================================================================================
256
257 STDAPI DllRegisterServer( void )
258 {
259 IRunnableTask * pTask = NULL;
260 HRESULT err;
261 BOOL ok;
262 CString s;
263
264 dlog( kDebugLevelTrace, "DllRegisterServer\n" );
265
266 ok = s.LoadString( IDS_NAME );
267 require_action( ok, exit, err = E_UNEXPECTED );
268
269 err = RegisterServer( gInstance, CLSID_ExplorerBar, s );
270 require_noerr( err, exit );
271
272 err = RegisterCOMCategory( CLSID_ExplorerBar, CATID_InfoBand, TRUE );
273 require_noerr( err, exit );
274
275 // <rdar://problem/4130635> Clear IE cache so it will rebuild the cache when it runs next. This
276 // will allow us to install and not reboot
277
278 err = CoCreateInstance(CLSID_CompCatCacheDaemon, NULL, CLSCTX_INPROC, IID_IRunnableTask, (void**) &pTask);
279 require_noerr( err, exit );
280
281 pTask->Run();
282 pTask->Release();
283
284 exit:
285 return( err );
286 }
287
288 //===========================================================================================================================
289 // DllUnregisterServer
290 //===========================================================================================================================
291
292 STDAPI DllUnregisterServer( void )
293 {
294 HRESULT err;
295
296 dlog( kDebugLevelTrace, "DllUnregisterServer\n" );
297
298 err = RegisterCOMCategory( CLSID_ExplorerBar, CATID_InfoBand, FALSE );
299 require_noerr( err, exit );
300
301 err = UnregisterServer( CLSID_ExplorerBar );
302 require_noerr( err, exit );
303
304 exit:
305 return( err );
306 }
307
308 #if 0
309 #pragma mark -
310 #pragma mark == MFC Support ==
311 #endif
312
313 //===========================================================================================================================
314 // MFCDLLProcessAttach
315 //===========================================================================================================================
316
317 DEBUG_LOCAL OSStatus MFCDLLProcessAttach( HINSTANCE inInstance )
318 {
319 wchar_t resource[MAX_PATH];
320 OSStatus err;
321 _AFX_THREAD_STATE * threadState;
322 AFX_MODULE_STATE * previousModuleState;
323 BOOL ok;
324 int res;
325 CWinApp * app;
326
327 app = NULL;
328
329 // Simulate what is done in dllmodul.cpp.
330
331 threadState = AfxGetThreadState();
332 check( threadState );
333 previousModuleState = threadState->m_pPrevModuleState;
334
335 ok = AfxWinInit( inInstance, NULL, TEXT( "" ), 0 );
336 require_action( ok, exit, err = kUnknownErr );
337
338 app = AfxGetApp();
339 require_action( ok, exit, err = kNotInitializedErr );
340
341 // Before we load the resources, let's load the error string
342
343 // errorMessage.LoadString( IDS_REINSTALL );
344 // errorCaption.LoadString( IDS_REINSTALL_CAPTION );
345
346 // Load Resources
347
348 res = PathForResource( inInstance, L"ExplorerPluginResources.dll", resource, MAX_PATH );
349
350 err = translate_errno( res != 0, kUnknownErr, kUnknownErr );
351 require_noerr( err, exit );
352
353 g_nonLocalizedResources = LoadLibrary( resource );
354 translate_errno( g_nonLocalizedResources, GetLastError(), kUnknownErr );
355 require_noerr( err, exit );
356
357 g_nonLocalizedResourcesName = resource;
358
359 res = PathForResource( inInstance, L"ExplorerPluginLocalized.dll", resource, MAX_PATH );
360 err = translate_errno( res != 0, kUnknownErr, kUnknownErr );
361 require_noerr( err, exit );
362
363 g_localizedResources = LoadLibrary( resource );
364 translate_errno( g_localizedResources, GetLastError(), kUnknownErr );
365 require_noerr( err, exit );
366
367 AfxSetResourceHandle( g_localizedResources );
368
369 ok = app->InitInstance();
370 require_action( ok, exit, err = kUnknownErr );
371
372 threadState->m_pPrevModuleState = previousModuleState;
373 threadState = NULL;
374 AfxInitLocalData( inInstance );
375 err = kNoErr;
376
377 exit:
378 if( err )
379 {
380 if( app )
381 {
382 app->ExitInstance();
383 }
384 AfxWinTerm();
385 }
386 if( threadState )
387 {
388 threadState->m_pPrevModuleState = previousModuleState;
389 }
390 return( err );
391 }
392
393 //===========================================================================================================================
394 // MFCDLLProcessDetach
395 //===========================================================================================================================
396
397 DEBUG_LOCAL void MFCDLLProcessDetach( HINSTANCE inInstance )
398 {
399 CWinApp * app;
400
401 // Simulate what is done in dllmodul.cpp.
402
403 app = AfxGetApp();
404 if( app )
405 {
406 app->ExitInstance();
407 }
408
409 #if( DEBUG )
410 if( AfxGetModuleThreadState()->m_nTempMapLock != 0 )
411 {
412 dlog( kDebugLevelWarning, "Warning: Temp map lock count non-zero (%ld).\n", AfxGetModuleThreadState()->m_nTempMapLock );
413 }
414 #endif
415
416 AfxLockTempMaps();
417 AfxUnlockTempMaps( -1 );
418
419 // Terminate the library before destructors are called.
420
421 AfxWinTerm();
422 AfxTermLocalData( inInstance, TRUE );
423 }
424
425 //===========================================================================================================================
426 // MFCDLLFinalize
427 //===========================================================================================================================
428
429 DEBUG_LOCAL void MFCDLLThreadDetach( HINSTANCE inInstance )
430 {
431 // Simulate what is done in dllmodul.cpp.
432
433 #if( DEBUG )
434 if( AfxGetModuleThreadState()->m_nTempMapLock != 0 )
435 {
436 dlog( kDebugLevelWarning, "Warning: Temp map lock count non-zero (%ld).\n", AfxGetModuleThreadState()->m_nTempMapLock );
437 }
438 #endif
439
440 AfxLockTempMaps();
441 AfxUnlockTempMaps( -1 );
442 AfxTermThread( inInstance );
443 }
444
445 #if 0
446 #pragma mark -
447 #pragma mark == Utilities ==
448 #endif
449
450 //===========================================================================================================================
451 // RegisterServer
452 //===========================================================================================================================
453
454 DEBUG_LOCAL OSStatus RegisterServer( HINSTANCE inInstance, CLSID inCLSID, LPCTSTR inName )
455 {
456 typedef struct RegistryBuilder RegistryBuilder;
457 struct RegistryBuilder
458 {
459 HKEY rootKey;
460 LPCTSTR subKey;
461 LPCTSTR valueName;
462 LPCTSTR data;
463 };
464
465 OSStatus err;
466 LPWSTR clsidWideString;
467 TCHAR clsidString[ 64 ];
468 DWORD nChars;
469 size_t n;
470 size_t i;
471 HKEY key;
472 TCHAR keyName[ MAX_PATH ];
473 TCHAR moduleName[ MAX_PATH ] = TEXT( "" );
474 TCHAR data[ MAX_PATH ];
475 RegistryBuilder entries[] =
476 {
477 { HKEY_CLASSES_ROOT, TEXT( "CLSID\\%s" ), NULL, inName },
478 { HKEY_CLASSES_ROOT, TEXT( "CLSID\\%s\\InprocServer32" ), NULL, moduleName },
479 { HKEY_CLASSES_ROOT, TEXT( "CLSID\\%s\\InprocServer32" ), TEXT( "ThreadingModel" ), TEXT( "Apartment" ) }
480 };
481 DWORD size;
482 OSVERSIONINFO versionInfo;
483
484 // Convert the CLSID to a string based on the encoding of this code (ANSI or Unicode).
485
486 err = StringFromIID( inCLSID, &clsidWideString );
487 require_noerr( err, exit );
488 require_action( clsidWideString, exit, err = kNoMemoryErr );
489
490 #ifdef UNICODE
491 lstrcpyn( clsidString, clsidWideString, sizeof_array( clsidString ) );
492 CoTaskMemFree( clsidWideString );
493 #else
494 nChars = WideCharToMultiByte( CP_ACP, 0, clsidWideString, -1, clsidString, sizeof_array( clsidString ), NULL, NULL );
495 err = translate_errno( nChars > 0, (OSStatus) GetLastError(), kUnknownErr );
496 CoTaskMemFree( clsidWideString );
497 require_noerr( err, exit );
498 #endif
499
500 // Register the CLSID entries.
501
502 nChars = GetModuleFileName( inInstance, moduleName, sizeof_array( moduleName ) );
503 err = translate_errno( nChars > 0, (OSStatus) GetLastError(), kUnknownErr );
504 require_noerr( err, exit );
505
506 n = sizeof_array( entries );
507 for( i = 0; i < n; ++i )
508 {
509 wsprintf( keyName, entries[ i ].subKey, clsidString );
510 err = RegCreateKeyEx( entries[ i ].rootKey, keyName, 0, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &key, NULL );
511 require_noerr( err, exit );
512
513 size = (DWORD)( ( lstrlen( entries[ i ].data ) + 1 ) * sizeof( TCHAR ) );
514 err = RegSetValueEx( key, entries[ i ].valueName, 0, REG_SZ, (LPBYTE) entries[ i ].data, size );
515 RegCloseKey( key );
516 require_noerr( err, exit );
517 }
518
519 // If running on NT, register the extension as approved.
520
521 versionInfo.dwOSVersionInfoSize = sizeof( versionInfo );
522 GetVersionEx( &versionInfo );
523 if( versionInfo.dwPlatformId == VER_PLATFORM_WIN32_NT )
524 {
525 lstrcpyn( keyName, TEXT( "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Shell Extensions\\Approved" ), sizeof_array( keyName ) );
526 err = RegCreateKeyEx( HKEY_LOCAL_MACHINE, keyName, 0, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &key, NULL );
527 require_noerr( err, exit );
528
529 lstrcpyn( data, inName, sizeof_array( data ) );
530 size = (DWORD)( ( lstrlen( data ) + 1 ) * sizeof( TCHAR ) );
531 err = RegSetValueEx( key, clsidString, 0, REG_SZ, (LPBYTE) data, size );
532 RegCloseKey( key );
533 }
534
535 // register toolbar button
536 lstrcpyn( keyName, TEXT( "SOFTWARE\\Microsoft\\Internet Explorer\\Extensions\\{7F9DB11C-E358-4ca6-A83D-ACC663939424}"), sizeof_array( keyName ) );
537 err = RegCreateKeyEx( HKEY_LOCAL_MACHINE, keyName, 0, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &key, NULL );
538 require_noerr( err, exit );
539
540 lstrcpyn( data, L"Yes", sizeof_array( data ) );
541 size = (DWORD)( ( lstrlen( data ) + 1 ) * sizeof( TCHAR ) );
542 RegSetValueEx( key, L"Default Visible", 0, REG_SZ, (LPBYTE) data, size );
543
544 lstrcpyn( data, inName, sizeof_array( data ) );
545 size = (DWORD)( ( lstrlen( data ) + 1 ) * sizeof( TCHAR ) );
546 RegSetValueEx( key, L"ButtonText", 0, REG_SZ, (LPBYTE) data, size );
547
548 lstrcpyn( data, L"{E0DD6CAB-2D10-11D2-8F1A-0000F87ABD16}", sizeof_array( data ) );
549 size = (DWORD)( ( lstrlen( data ) + 1 ) * sizeof( TCHAR ) );
550 RegSetValueEx( key, L"CLSID", 0, REG_SZ, (LPBYTE) data, size );
551
552 lstrcpyn( data, clsidString, sizeof_array( data ) );
553 size = (DWORD)( ( lstrlen( data ) + 1 ) * sizeof( TCHAR ) );
554 RegSetValueEx( key, L"BandCLSID", 0, REG_SZ, (LPBYTE) data, size );
555
556 // check if we're running XP or later
557 if ( ( versionInfo.dwPlatformId == VER_PLATFORM_WIN32_NT ) &&
558 ( versionInfo.dwMajorVersion == 5 ) &&
559 ( versionInfo.dwMinorVersion >= 1 ) )
560 {
561 wsprintf( data, L"%s,%d", (LPCTSTR) g_nonLocalizedResourcesName, IDI_BUTTON_XP );
562 size = (DWORD)( ( lstrlen( data ) + 1 ) * sizeof( TCHAR ) );
563 RegSetValueEx( key, L"Icon", 0, REG_SZ, (LPBYTE) data, size);
564
565 wsprintf( data, L"%s,%d", (LPCTSTR) g_nonLocalizedResourcesName, IDI_BUTTON_XP );
566 size = (DWORD)( ( lstrlen( data ) + 1 ) * sizeof( TCHAR ) );
567 RegSetValueEx( key, L"HotIcon", 0, REG_SZ, (LPBYTE) data, size);
568 }
569 else
570 {
571 wsprintf( data, L"%s,%d", (LPCTSTR) g_nonLocalizedResourcesName, IDI_BUTTON_2K );
572 size = (DWORD)( ( lstrlen( data ) + 1 ) * sizeof( TCHAR ) );
573 RegSetValueEx( key, L"Icon", 0, REG_SZ, (LPBYTE) data, size);
574
575 wsprintf( data, L"%s,%d", (LPCTSTR) g_nonLocalizedResourcesName, IDI_BUTTON_2K );
576 size = (DWORD)( ( lstrlen( data ) + 1 ) * sizeof( TCHAR ) );
577 RegSetValueEx( key, L"HotIcon", 0, REG_SZ, (LPBYTE) data, size);
578 }
579
580 RegCloseKey( key );
581
582 exit:
583 return( err );
584 }
585
586 //===========================================================================================================================
587 // RegisterCOMCategory
588 //===========================================================================================================================
589
590 DEBUG_LOCAL OSStatus RegisterCOMCategory( CLSID inCLSID, CATID inCategoryID, BOOL inRegister )
591 {
592 HRESULT err;
593 ICatRegister * cat;
594
595 err = CoInitialize( NULL );
596 require( SUCCEEDED( err ), exit );
597
598 err = CoCreateInstance( CLSID_StdComponentCategoriesMgr, NULL, CLSCTX_INPROC_SERVER, IID_ICatRegister, (LPVOID *) &cat );
599 check( SUCCEEDED( err ) );
600 if( SUCCEEDED( err ) )
601 {
602 if( inRegister )
603 {
604 err = cat->RegisterClassImplCategories( inCLSID, 1, &inCategoryID );
605 check_noerr( err );
606 }
607 else
608 {
609 err = cat->UnRegisterClassImplCategories( inCLSID, 1, &inCategoryID );
610 check_noerr( err );
611 }
612 cat->Release();
613 }
614 CoUninitialize();
615
616 exit:
617 return( err );
618 }
619
620
621 //===========================================================================================================================
622 // UnregisterServer
623 //===========================================================================================================================
624
625 DEBUG_LOCAL OSStatus UnregisterServer( CLSID inCLSID )
626 {
627 OSStatus err = 0;
628 LPWSTR clsidWideString;
629 TCHAR clsidString[ 64 ];
630 HKEY key;
631 TCHAR keyName[ MAX_PATH * 2 ];
632 OSVERSIONINFO versionInfo;
633
634 // Convert the CLSID to a string based on the encoding of this code (ANSI or Unicode).
635
636 err = StringFromIID( inCLSID, &clsidWideString );
637 require_noerr( err, exit );
638 require_action( clsidWideString, exit, err = kNoMemoryErr );
639
640 #ifdef UNICODE
641 lstrcpyn( clsidString, clsidWideString, sizeof_array( clsidString ) );
642 CoTaskMemFree( clsidWideString );
643 #else
644 nChars = WideCharToMultiByte( CP_ACP, 0, clsidWideString, -1, clsidString, sizeof_array( clsidString ), NULL, NULL );
645 err = translate_errno( nChars > 0, (OSStatus) GetLastError(), kUnknownErr );
646 CoTaskMemFree( clsidWideString );
647 require_noerr( err, exit );
648 #endif
649
650 wsprintf( keyName, L"CLSID\\%s", clsidString );
651 MyRegDeleteKey( HKEY_CLASSES_ROOT, keyName );
652
653 // If running on NT, de-register the extension as approved.
654
655 versionInfo.dwOSVersionInfoSize = sizeof( versionInfo );
656 GetVersionEx( &versionInfo );
657 if( versionInfo.dwPlatformId == VER_PLATFORM_WIN32_NT )
658 {
659 lstrcpyn( keyName, TEXT( "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Shell Extensions\\Approved" ), sizeof_array( keyName ) );
660 err = RegCreateKeyEx( HKEY_LOCAL_MACHINE, keyName, 0, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &key, NULL );
661 require_noerr( err, exit );
662
663 RegDeleteValue( key, clsidString );
664
665 err = RegCloseKey( key );
666 require_noerr( err, exit );
667 }
668
669 // de-register toolbar button
670
671 lstrcpyn( keyName, TEXT( "SOFTWARE\\Microsoft\\Internet Explorer\\Extensions\\{7F9DB11C-E358-4ca6-A83D-ACC663939424}"), sizeof_array( keyName ) );
672 MyRegDeleteKey( HKEY_LOCAL_MACHINE, keyName );
673
674 exit:
675 return( err );
676 }
677
678
679
680 //===========================================================================================================================
681 // MyRegDeleteKey
682 //===========================================================================================================================
683
684 DEBUG_LOCAL OSStatus MyRegDeleteKey( HKEY hKeyRoot, LPTSTR lpSubKey )
685 {
686 LPTSTR lpEnd;
687 OSStatus err;
688 DWORD dwSize;
689 TCHAR szName[MAX_PATH];
690 HKEY hKey;
691 FILETIME ftWrite;
692
693 // First, see if we can delete the key without having to recurse.
694
695 err = RegDeleteKey( hKeyRoot, lpSubKey );
696
697 if ( !err )
698 {
699 goto exit;
700 }
701
702 err = RegOpenKeyEx( hKeyRoot, lpSubKey, 0, KEY_READ, &hKey );
703 require_noerr( err, exit );
704
705 // Check for an ending slash and add one if it is missing.
706
707 lpEnd = lpSubKey + lstrlen(lpSubKey);
708
709 if ( *( lpEnd - 1 ) != TEXT( '\\' ) )
710 {
711 *lpEnd = TEXT('\\');
712 lpEnd++;
713 *lpEnd = TEXT('\0');
714 }
715
716 // Enumerate the keys
717
718 dwSize = MAX_PATH;
719 err = RegEnumKeyEx(hKey, 0, szName, &dwSize, NULL, NULL, NULL, &ftWrite);
720
721 if ( !err )
722 {
723 do
724 {
725 lstrcpy (lpEnd, szName);
726
727 if ( !MyRegDeleteKey( hKeyRoot, lpSubKey ) )
728 {
729 break;
730 }
731
732 dwSize = MAX_PATH;
733
734 err = RegEnumKeyEx( hKey, 0, szName, &dwSize, NULL, NULL, NULL, &ftWrite );
735
736 }
737 while ( !err );
738 }
739
740 lpEnd--;
741 *lpEnd = TEXT('\0');
742
743 RegCloseKey( hKey );
744
745 // Try again to delete the key.
746
747 err = RegDeleteKey(hKeyRoot, lpSubKey);
748 require_noerr( err, exit );
749
750 exit:
751
752 return err;
753 }