]> git.saurik.com Git - apple/mdnsresponder.git/blob - Clients/ExplorerPlugin/ExplorerPlugin.cpp
mDNSResponder-212.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.10 2009/03/30 18:51:04 herscher
21 <rdar://problem/5925472> Current Bonjour code does not compile on Windows
22 <rdar://problem/5187308> Move build train to Visual Studio 2005
23
24 Revision 1.9 2006/08/14 23:24:00 cheshire
25 Re-licensed mDNSResponder daemon source code under Apache License, Version 2.0
26
27 Revision 1.8 2005/06/30 18:01:54 shersche
28 <rdar://problem/4130635> Cause IE to rebuild cache so we don't have to reboot following an install.
29
30 Revision 1.7 2005/02/23 02:00:45 shersche
31 <rdar://problem/4014479> Delete all the registry entries when component is unregistered
32
33 Revision 1.6 2005/01/25 17:56:45 shersche
34 <rdar://problem/3911084> Load resource DLLs, get icons and bitmaps from resource DLLs
35 Bug #: 3911084
36
37 Revision 1.5 2004/09/15 10:33:54 shersche
38 <rdar://problem/3721611> Install XP toolbar button (8 bit mask) if running on XP platform, otherwise install 1 bit mask toolbar button
39 Bug #: 3721611
40
41 Revision 1.4 2004/07/13 21:24:21 rpantos
42 Fix for <rdar://problem/3701120>.
43
44 Revision 1.3 2004/06/26 14:12:07 shersche
45 Register the toolbar button
46
47 Revision 1.2 2004/06/24 20:09:39 shersche
48 Change text
49 Submitted by: herscher
50
51 Revision 1.1 2004/06/18 04:34:59 rpantos
52 Move to Clients from mDNSWindows
53
54 Revision 1.1 2004/01/30 03:01:56 bradley
55 Explorer Plugin to browse for DNS-SD advertised Web and FTP servers from within Internet Explorer.
56
57 */
58
59 #include "StdAfx.h"
60
61 // The following 2 includes have to be in this order and INITGUID must be defined here, before including the file
62 // that specifies the GUID(s), and nowhere else. The reason for this is that initguid.h doesn't provide separate
63 // define and declare macros for GUIDs so you have to #define INITGUID in the single file where you want to define
64 // your GUID then in all the other files that just need the GUID declared, INITGUID must not be defined.
65
66 #define INITGUID
67 #include <initguid.h>
68 #include "ExplorerPlugin.h"
69
70 #include <comcat.h>
71 #include <Shlwapi.h>
72
73 #include "CommonServices.h"
74 #include "DebugServices.h"
75
76 #include "ClassFactory.h"
77 #include "Resource.h"
78
79 #include "loclibrary.h"
80
81 // MFC Debugging
82
83 #ifdef _DEBUG
84 #define new DEBUG_NEW
85 #undef THIS_FILE
86 static char THIS_FILE[] = __FILE__;
87 #endif
88
89 #if 0
90 #pragma mark == Prototypes ==
91 #endif
92
93 //===========================================================================================================================
94 // Prototypes
95 //===========================================================================================================================
96
97 // Utilities
98
99 DEBUG_LOCAL OSStatus RegisterServer( HINSTANCE inInstance, CLSID inCLSID, LPCTSTR inName );
100 DEBUG_LOCAL OSStatus RegisterCOMCategory( CLSID inCLSID, CATID inCategoryID, BOOL inRegister );
101 DEBUG_LOCAL OSStatus UnregisterServer( CLSID inCLSID );
102 DEBUG_LOCAL OSStatus MyRegDeleteKey( HKEY hKeyRoot, LPTSTR lpSubKey );
103
104 // Stash away pointers to our resource DLLs
105
106 static HINSTANCE g_nonLocalizedResources = NULL;
107 static CString g_nonLocalizedResourcesName;
108 static HINSTANCE g_localizedResources = NULL;
109
110 HINSTANCE
111 GetNonLocalizedResources()
112 {
113 return g_nonLocalizedResources;
114 }
115
116 HINSTANCE
117 GetLocalizedResources()
118 {
119 return g_localizedResources;
120 }
121
122 // This is the class GUID for an undocumented hook into IE that will allow us to register
123 // and have IE notice our new ExplorerBar without rebooting.
124 // {8C7461EF-2B13-11d2-BE35-3078302C2030}
125
126 DEFINE_GUID(CLSID_CompCatCacheDaemon,
127 0x8C7461EF, 0x2b13, 0x11d2, 0xbe, 0x35, 0x30, 0x78, 0x30, 0x2c, 0x20, 0x30);
128
129
130 #if 0
131 #pragma mark == Globals ==
132 #endif
133
134 //===========================================================================================================================
135 // Globals
136 //===========================================================================================================================
137
138 HINSTANCE gInstance = NULL;
139 int gDLLRefCount = 0;
140 CExplorerPluginApp gApp;
141
142 #if 0
143 #pragma mark -
144 #pragma mark == DLL Exports ==
145 #endif
146
147 //===========================================================================================================================
148 // CExplorerPluginApp::CExplorerPluginApp
149 //===========================================================================================================================
150
151 IMPLEMENT_DYNAMIC(CExplorerPluginApp, CWinApp);
152
153 CExplorerPluginApp::CExplorerPluginApp()
154 {
155 }
156
157
158 //===========================================================================================================================
159 // CExplorerPluginApp::~CExplorerPluginApp
160 //===========================================================================================================================
161
162 CExplorerPluginApp::~CExplorerPluginApp()
163 {
164 }
165
166
167 //===========================================================================================================================
168 // CExplorerPluginApp::InitInstance
169 //===========================================================================================================================
170
171 BOOL
172 CExplorerPluginApp::InitInstance()
173 {
174 wchar_t resource[MAX_PATH];
175 OSStatus err;
176 int res;
177 HINSTANCE inInstance;
178
179 inInstance = AfxGetInstanceHandle();
180 gInstance = inInstance;
181
182 debug_initialize( kDebugOutputTypeWindowsEventLog, "DNSServices Bar", inInstance );
183 debug_set_property( kDebugPropertyTagPrintLevel, kDebugLevelTrace );
184 dlog( kDebugLevelTrace, "\nCCPApp::InitInstance\n" );
185
186 res = PathForResource( inInstance, L"ExplorerPluginResources.dll", resource, MAX_PATH );
187
188 err = translate_errno( res != 0, kUnknownErr, kUnknownErr );
189 require_noerr( err, exit );
190
191 g_nonLocalizedResources = LoadLibrary( resource );
192 translate_errno( g_nonLocalizedResources, GetLastError(), kUnknownErr );
193 require_noerr( err, exit );
194
195 g_nonLocalizedResourcesName = resource;
196
197 res = PathForResource( inInstance, L"ExplorerPluginLocalized.dll", resource, MAX_PATH );
198 err = translate_errno( res != 0, kUnknownErr, kUnknownErr );
199 require_noerr( err, exit );
200
201 g_localizedResources = LoadLibrary( resource );
202 translate_errno( g_localizedResources, GetLastError(), kUnknownErr );
203 require_noerr( err, exit );
204
205 AfxSetResourceHandle( g_localizedResources );
206
207 exit:
208
209 return TRUE;
210 }
211
212
213 //===========================================================================================================================
214 // CExplorerPluginApp::ExitInstance
215 //===========================================================================================================================
216
217 int
218 CExplorerPluginApp::ExitInstance()
219 {
220 return 0;
221 }
222
223
224
225 //===========================================================================================================================
226 // DllCanUnloadNow
227 //===========================================================================================================================
228
229 STDAPI DllCanUnloadNow( void )
230 {
231 dlog( kDebugLevelTrace, "DllCanUnloadNow (refCount=%d)\n", gDLLRefCount );
232
233 return( gDLLRefCount == 0 );
234 }
235
236 //===========================================================================================================================
237 // DllGetClassObject
238 //===========================================================================================================================
239
240 STDAPI DllGetClassObject( REFCLSID inCLSID, REFIID inIID, LPVOID *outResult )
241 {
242 HRESULT err;
243 BOOL ok;
244 ClassFactory * factory;
245
246 dlog( kDebugLevelTrace, "DllGetClassObject\n" );
247
248 *outResult = NULL;
249
250 // Check if the class ID is supported.
251
252 ok = IsEqualCLSID( inCLSID, CLSID_ExplorerBar );
253 require_action_quiet( ok, exit, err = CLASS_E_CLASSNOTAVAILABLE );
254
255 // Create the ClassFactory object.
256
257 factory = NULL;
258 try
259 {
260 factory = new ClassFactory( inCLSID );
261 }
262 catch( ... )
263 {
264 // Do not let exception escape.
265 }
266 require_action( factory, exit, err = E_OUTOFMEMORY );
267
268 // Query for the specified interface. Release the factory since QueryInterface retains it.
269
270 err = factory->QueryInterface( inIID, outResult );
271 factory->Release();
272
273 exit:
274 return( err );
275 }
276
277 //===========================================================================================================================
278 // DllRegisterServer
279 //===========================================================================================================================
280
281 STDAPI DllRegisterServer( void )
282 {
283 IRunnableTask * pTask = NULL;
284 HRESULT err;
285 BOOL ok;
286 CString s;
287
288 dlog( kDebugLevelTrace, "DllRegisterServer\n" );
289
290 ok = s.LoadString( IDS_NAME );
291 require_action( ok, exit, err = E_UNEXPECTED );
292
293 err = RegisterServer( gInstance, CLSID_ExplorerBar, s );
294 require_noerr( err, exit );
295
296 err = RegisterCOMCategory( CLSID_ExplorerBar, CATID_InfoBand, TRUE );
297 require_noerr( err, exit );
298
299 // <rdar://problem/4130635> Clear IE cache so it will rebuild the cache when it runs next. This
300 // will allow us to install and not reboot
301
302 err = CoCreateInstance(CLSID_CompCatCacheDaemon, NULL, CLSCTX_INPROC, IID_IRunnableTask, (void**) &pTask);
303 require_noerr( err, exit );
304
305 pTask->Run();
306 pTask->Release();
307
308 exit:
309 return( err );
310 }
311
312 //===========================================================================================================================
313 // DllUnregisterServer
314 //===========================================================================================================================
315
316 STDAPI DllUnregisterServer( void )
317 {
318 HRESULT err;
319
320 dlog( kDebugLevelTrace, "DllUnregisterServer\n" );
321
322 err = RegisterCOMCategory( CLSID_ExplorerBar, CATID_InfoBand, FALSE );
323 require_noerr( err, exit );
324
325 err = UnregisterServer( CLSID_ExplorerBar );
326 require_noerr( err, exit );
327
328 exit:
329 return( err );
330 }
331
332
333 #if 0
334 #pragma mark -
335 #pragma mark == Utilities ==
336 #endif
337
338 //===========================================================================================================================
339 // RegisterServer
340 //===========================================================================================================================
341
342 DEBUG_LOCAL OSStatus RegisterServer( HINSTANCE inInstance, CLSID inCLSID, LPCTSTR inName )
343 {
344 typedef struct RegistryBuilder RegistryBuilder;
345 struct RegistryBuilder
346 {
347 HKEY rootKey;
348 LPCTSTR subKey;
349 LPCTSTR valueName;
350 LPCTSTR data;
351 };
352
353 OSStatus err;
354 LPWSTR clsidWideString;
355 TCHAR clsidString[ 64 ];
356 DWORD nChars;
357 size_t n;
358 size_t i;
359 HKEY key;
360 TCHAR keyName[ MAX_PATH ];
361 TCHAR moduleName[ MAX_PATH ] = TEXT( "" );
362 TCHAR data[ MAX_PATH ];
363 RegistryBuilder entries[] =
364 {
365 { HKEY_CLASSES_ROOT, TEXT( "CLSID\\%s" ), NULL, inName },
366 { HKEY_CLASSES_ROOT, TEXT( "CLSID\\%s\\InprocServer32" ), NULL, moduleName },
367 { HKEY_CLASSES_ROOT, TEXT( "CLSID\\%s\\InprocServer32" ), TEXT( "ThreadingModel" ), TEXT( "Apartment" ) }
368 };
369 DWORD size;
370 OSVERSIONINFO versionInfo;
371
372 // Convert the CLSID to a string based on the encoding of this code (ANSI or Unicode).
373
374 err = StringFromIID( inCLSID, &clsidWideString );
375 require_noerr( err, exit );
376 require_action( clsidWideString, exit, err = kNoMemoryErr );
377
378 #ifdef UNICODE
379 lstrcpyn( clsidString, clsidWideString, sizeof_array( clsidString ) );
380 CoTaskMemFree( clsidWideString );
381 #else
382 nChars = WideCharToMultiByte( CP_ACP, 0, clsidWideString, -1, clsidString, sizeof_array( clsidString ), NULL, NULL );
383 err = translate_errno( nChars > 0, (OSStatus) GetLastError(), kUnknownErr );
384 CoTaskMemFree( clsidWideString );
385 require_noerr( err, exit );
386 #endif
387
388 // Register the CLSID entries.
389
390 nChars = GetModuleFileName( inInstance, moduleName, sizeof_array( moduleName ) );
391 err = translate_errno( nChars > 0, (OSStatus) GetLastError(), kUnknownErr );
392 require_noerr( err, exit );
393
394 n = sizeof_array( entries );
395 for( i = 0; i < n; ++i )
396 {
397 wsprintf( keyName, entries[ i ].subKey, clsidString );
398 err = RegCreateKeyEx( entries[ i ].rootKey, keyName, 0, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &key, NULL );
399 require_noerr( err, exit );
400
401 size = (DWORD)( ( lstrlen( entries[ i ].data ) + 1 ) * sizeof( TCHAR ) );
402 err = RegSetValueEx( key, entries[ i ].valueName, 0, REG_SZ, (LPBYTE) entries[ i ].data, size );
403 RegCloseKey( key );
404 require_noerr( err, exit );
405 }
406
407 // If running on NT, register the extension as approved.
408
409 versionInfo.dwOSVersionInfoSize = sizeof( versionInfo );
410 GetVersionEx( &versionInfo );
411 if( versionInfo.dwPlatformId == VER_PLATFORM_WIN32_NT )
412 {
413 lstrcpyn( keyName, TEXT( "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Shell Extensions\\Approved" ), sizeof_array( keyName ) );
414 err = RegCreateKeyEx( HKEY_LOCAL_MACHINE, keyName, 0, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &key, NULL );
415 require_noerr( err, exit );
416
417 lstrcpyn( data, inName, sizeof_array( data ) );
418 size = (DWORD)( ( lstrlen( data ) + 1 ) * sizeof( TCHAR ) );
419 err = RegSetValueEx( key, clsidString, 0, REG_SZ, (LPBYTE) data, size );
420 RegCloseKey( key );
421 }
422
423 // register toolbar button
424 lstrcpyn( keyName, TEXT( "SOFTWARE\\Microsoft\\Internet Explorer\\Extensions\\{7F9DB11C-E358-4ca6-A83D-ACC663939424}"), sizeof_array( keyName ) );
425 err = RegCreateKeyEx( HKEY_LOCAL_MACHINE, keyName, 0, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &key, NULL );
426 require_noerr( err, exit );
427
428 lstrcpyn( data, L"Yes", sizeof_array( data ) );
429 size = (DWORD)( ( lstrlen( data ) + 1 ) * sizeof( TCHAR ) );
430 RegSetValueEx( key, L"Default Visible", 0, REG_SZ, (LPBYTE) data, size );
431
432 lstrcpyn( data, inName, sizeof_array( data ) );
433 size = (DWORD)( ( lstrlen( data ) + 1 ) * sizeof( TCHAR ) );
434 RegSetValueEx( key, L"ButtonText", 0, REG_SZ, (LPBYTE) data, size );
435
436 lstrcpyn( data, L"{E0DD6CAB-2D10-11D2-8F1A-0000F87ABD16}", sizeof_array( data ) );
437 size = (DWORD)( ( lstrlen( data ) + 1 ) * sizeof( TCHAR ) );
438 RegSetValueEx( key, L"CLSID", 0, REG_SZ, (LPBYTE) data, size );
439
440 lstrcpyn( data, clsidString, sizeof_array( data ) );
441 size = (DWORD)( ( lstrlen( data ) + 1 ) * sizeof( TCHAR ) );
442 RegSetValueEx( key, L"BandCLSID", 0, REG_SZ, (LPBYTE) data, size );
443
444 // check if we're running XP or later
445 if ( ( versionInfo.dwPlatformId == VER_PLATFORM_WIN32_NT ) &&
446 ( versionInfo.dwMajorVersion == 5 ) &&
447 ( versionInfo.dwMinorVersion >= 1 ) )
448 {
449 wsprintf( data, L"%s,%d", (LPCTSTR) g_nonLocalizedResourcesName, IDI_BUTTON_XP );
450 size = (DWORD)( ( lstrlen( data ) + 1 ) * sizeof( TCHAR ) );
451 RegSetValueEx( key, L"Icon", 0, REG_SZ, (LPBYTE) data, size);
452
453 wsprintf( data, L"%s,%d", (LPCTSTR) g_nonLocalizedResourcesName, IDI_BUTTON_XP );
454 size = (DWORD)( ( lstrlen( data ) + 1 ) * sizeof( TCHAR ) );
455 RegSetValueEx( key, L"HotIcon", 0, REG_SZ, (LPBYTE) data, size);
456 }
457 else
458 {
459 wsprintf( data, L"%s,%d", (LPCTSTR) g_nonLocalizedResourcesName, IDI_BUTTON_2K );
460 size = (DWORD)( ( lstrlen( data ) + 1 ) * sizeof( TCHAR ) );
461 RegSetValueEx( key, L"Icon", 0, REG_SZ, (LPBYTE) data, size);
462
463 wsprintf( data, L"%s,%d", (LPCTSTR) g_nonLocalizedResourcesName, IDI_BUTTON_2K );
464 size = (DWORD)( ( lstrlen( data ) + 1 ) * sizeof( TCHAR ) );
465 RegSetValueEx( key, L"HotIcon", 0, REG_SZ, (LPBYTE) data, size);
466 }
467
468 RegCloseKey( key );
469
470 exit:
471 return( err );
472 }
473
474 //===========================================================================================================================
475 // RegisterCOMCategory
476 //===========================================================================================================================
477
478 DEBUG_LOCAL OSStatus RegisterCOMCategory( CLSID inCLSID, CATID inCategoryID, BOOL inRegister )
479 {
480 HRESULT err;
481 ICatRegister * cat;
482
483 err = CoInitialize( NULL );
484 require( SUCCEEDED( err ), exit );
485
486 err = CoCreateInstance( CLSID_StdComponentCategoriesMgr, NULL, CLSCTX_INPROC_SERVER, IID_ICatRegister, (LPVOID *) &cat );
487 check( SUCCEEDED( err ) );
488 if( SUCCEEDED( err ) )
489 {
490 if( inRegister )
491 {
492 err = cat->RegisterClassImplCategories( inCLSID, 1, &inCategoryID );
493 check_noerr( err );
494 }
495 else
496 {
497 err = cat->UnRegisterClassImplCategories( inCLSID, 1, &inCategoryID );
498 check_noerr( err );
499 }
500 cat->Release();
501 }
502 CoUninitialize();
503
504 exit:
505 return( err );
506 }
507
508
509 //===========================================================================================================================
510 // UnregisterServer
511 //===========================================================================================================================
512
513 DEBUG_LOCAL OSStatus UnregisterServer( CLSID inCLSID )
514 {
515 OSStatus err = 0;
516 LPWSTR clsidWideString;
517 TCHAR clsidString[ 64 ];
518 HKEY key;
519 TCHAR keyName[ MAX_PATH * 2 ];
520 OSVERSIONINFO versionInfo;
521
522 // Convert the CLSID to a string based on the encoding of this code (ANSI or Unicode).
523
524 err = StringFromIID( inCLSID, &clsidWideString );
525 require_noerr( err, exit );
526 require_action( clsidWideString, exit, err = kNoMemoryErr );
527
528 #ifdef UNICODE
529 lstrcpyn( clsidString, clsidWideString, sizeof_array( clsidString ) );
530 CoTaskMemFree( clsidWideString );
531 #else
532 nChars = WideCharToMultiByte( CP_ACP, 0, clsidWideString, -1, clsidString, sizeof_array( clsidString ), NULL, NULL );
533 err = translate_errno( nChars > 0, (OSStatus) GetLastError(), kUnknownErr );
534 CoTaskMemFree( clsidWideString );
535 require_noerr( err, exit );
536 #endif
537
538 wsprintf( keyName, L"CLSID\\%s", clsidString );
539 MyRegDeleteKey( HKEY_CLASSES_ROOT, keyName );
540
541 // If running on NT, de-register the extension as approved.
542
543 versionInfo.dwOSVersionInfoSize = sizeof( versionInfo );
544 GetVersionEx( &versionInfo );
545 if( versionInfo.dwPlatformId == VER_PLATFORM_WIN32_NT )
546 {
547 lstrcpyn( keyName, TEXT( "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Shell Extensions\\Approved" ), sizeof_array( keyName ) );
548 err = RegCreateKeyEx( HKEY_LOCAL_MACHINE, keyName, 0, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &key, NULL );
549 require_noerr( err, exit );
550
551 RegDeleteValue( key, clsidString );
552
553 err = RegCloseKey( key );
554 require_noerr( err, exit );
555 }
556
557 // de-register toolbar button
558
559 lstrcpyn( keyName, TEXT( "SOFTWARE\\Microsoft\\Internet Explorer\\Extensions\\{7F9DB11C-E358-4ca6-A83D-ACC663939424}"), sizeof_array( keyName ) );
560 MyRegDeleteKey( HKEY_LOCAL_MACHINE, keyName );
561
562 exit:
563 return( err );
564 }
565
566
567
568 //===========================================================================================================================
569 // MyRegDeleteKey
570 //===========================================================================================================================
571
572 DEBUG_LOCAL OSStatus MyRegDeleteKey( HKEY hKeyRoot, LPTSTR lpSubKey )
573 {
574 LPTSTR lpEnd;
575 OSStatus err;
576 DWORD dwSize;
577 TCHAR szName[MAX_PATH];
578 HKEY hKey;
579 FILETIME ftWrite;
580
581 // First, see if we can delete the key without having to recurse.
582
583 err = RegDeleteKey( hKeyRoot, lpSubKey );
584
585 if ( !err )
586 {
587 goto exit;
588 }
589
590 err = RegOpenKeyEx( hKeyRoot, lpSubKey, 0, KEY_READ, &hKey );
591 require_noerr( err, exit );
592
593 // Check for an ending slash and add one if it is missing.
594
595 lpEnd = lpSubKey + lstrlen(lpSubKey);
596
597 if ( *( lpEnd - 1 ) != TEXT( '\\' ) )
598 {
599 *lpEnd = TEXT('\\');
600 lpEnd++;
601 *lpEnd = TEXT('\0');
602 }
603
604 // Enumerate the keys
605
606 dwSize = MAX_PATH;
607 err = RegEnumKeyEx(hKey, 0, szName, &dwSize, NULL, NULL, NULL, &ftWrite);
608
609 if ( !err )
610 {
611 do
612 {
613 lstrcpy (lpEnd, szName);
614
615 if ( !MyRegDeleteKey( hKeyRoot, lpSubKey ) )
616 {
617 break;
618 }
619
620 dwSize = MAX_PATH;
621
622 err = RegEnumKeyEx( hKey, 0, szName, &dwSize, NULL, NULL, NULL, &ftWrite );
623
624 }
625 while ( !err );
626 }
627
628 lpEnd--;
629 *lpEnd = TEXT('\0');
630
631 RegCloseKey( hKey );
632
633 // Try again to delete the key.
634
635 err = RegDeleteKey(hKeyRoot, lpSubKey);
636 require_noerr( err, exit );
637
638 exit:
639
640 return err;
641 }