- if ( m_regDomainsRef )
- {
- err = WSAAsyncSelect( DNSServiceRefSockFD( m_regDomainsRef ), m_hWnd, 0, 0 );
- check_noerr( err );
-
- DNSServiceRefDeallocate( m_regDomainsRef );
-
- m_regDomainsRef = NULL;
- }
-
- return err;
-}
-
-
-//---------------------------------------------------------------------------------------------------------------------------
-// CConfigPropertySheet::SetupRegistryNotifications
-//---------------------------------------------------------------------------------------------------------------------------
-
-OSStatus
-CConfigPropertySheet::SetupRegistryNotifications()
-{
- unsigned int threadId;
- OSStatus err;
-
- check( m_threadExited == NULL );
- check( m_thread == NULL );
-
- err = RegCreateKey( HKEY_LOCAL_MACHINE, kServiceParametersNode L"\\DynDNS\\State\\Hostnames", &m_statusKey );
- require_noerr( err, exit );
-
- m_threadExited = CreateEvent( NULL, FALSE, FALSE, NULL );
- err = translate_errno( m_threadExited, (OSStatus) GetLastError(), kUnknownErr );
- require_noerr( err, exit );
-
- // Create thread with _beginthreadex() instead of CreateThread() to avoid memory leaks when using static run-time
- // libraries. See <http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dllproc/base/createthread.asp>.
-
- m_thread = (HANDLE) _beginthreadex_compat( NULL, 0, WatchRegistry, this, 0, &threadId );
- err = translate_errno( m_thread, (OSStatus) GetLastError(), kUnknownErr );
- require_noerr( err, exit );
-
-exit:
-
- if ( err )
- {
- TearDownRegistryNotifications();
- }
-
- return err;
-}
-
-
-//---------------------------------------------------------------------------------------------------------------------------
-// CConfigPropertySheet::TearDownRegistryNotifications
-//---------------------------------------------------------------------------------------------------------------------------
-
-OSStatus
-CConfigPropertySheet::TearDownRegistryNotifications()
-{
- OSStatus err = kNoErr;
-
- if ( m_statusKey )
- {
- EnterCriticalSection( &m_lock );
-
- RegCloseKey( m_statusKey );
- m_statusKey = NULL;
-
- LeaveCriticalSection( &m_lock );
- }
-
- if ( m_threadExited )
- {
- err = WaitForSingleObject( m_threadExited, 5 * 1000 );
- require_noerr( err, exit );
- }
-
-exit:
-
- if ( m_threadExited )
- {
- CloseHandle( m_threadExited );
- m_threadExited = NULL;
- }
-
- if ( m_thread )
- {
- CloseHandle( m_thread );
- m_thread = NULL;
- }
-