// regtrace.cpp : Defines the class behaviors for the application. // #include "stdafx.h" #include "regtrace.h" #include "regtrdlg.h" #ifdef _DEBUG #undef THIS_FILE static char BASED_CODE THIS_FILE[] = __FILE__; #endif ///////////////////////////////////////////////////////////////////////////// // CRegTraceApp BEGIN_MESSAGE_MAP(CRegTraceApp, CWinApp) //{{AFX_MSG_MAP(CRegTraceApp) // NOTE - the ClassWizard will add and remove mapping macros here. // DO NOT EDIT what you see in these blocks of generated code! //}}AFX_MSG ON_COMMAND(ID_HELP, CWinApp::OnHelp) END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // CRegTraceApp construction CRegTraceApp::CRegTraceApp() { m_hRegKey = NULL; m_hRegMachineKey = NULL; m_szCmdLineServer[0] = '\0'; } ///////////////////////////////////////////////////////////////////////////// // The one and only CRegTraceApp object CRegTraceApp theApp; char CRegTraceApp::m_szDebugAsyncTrace[] = "SOFTWARE\\Microsoft\\MosTrace\\CurrentVersion\\DebugAsyncTrace"; ///////////////////////////////////////////////////////////////////////////// // CRegTraceApp initialization BOOL CRegTraceApp::InitInstance() { // Standard initialization // If you are not using these features and wish to reduce the size // of your final executable, you should remove from the following // the specific initialization routines you do not need. Enable3dControls(); LoadStdProfileSettings(); // Load standard INI file options (including MRU) // // check for cmd line param for remote server // m_szCmdLineServer[0] = '\0'; if ( m_lpCmdLine && m_lpCmdLine[0] == '\\' && m_lpCmdLine[1] == '\\' ) { LPSTR lpsz1, lpsz2; int i; for ( i=0, lpsz1=m_lpCmdLine, lpsz2=m_szCmdLineServer; iPostMessage( WM_COMMAND, IDOK, NULL ); return (DWORD)lError; } LONG CRegTraceApp::OpenTraceRegKey() { DWORD dwDisposition; LONG lError; // // check for cache of the remote hkey value // if ( IsRemoteMsnServer() ) { DWORD dwThreadId; HANDLE hThread = ::CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)ConnectThread, (LPVOID)&m_dlgConnect, 0, &dwThreadId ); if ( hThread == NULL ) { return GetLastError(); } if ( m_dlgConnect.DoModal() == IDCANCEL ) { return -1; } WaitForSingleObject( hThread, INFINITE ); GetExitCodeThread( hThread, (LPDWORD)&lError ); CloseHandle( hThread ); if ( lError != ERROR_SUCCESS ) { return lError; } } HKEY hRoot = IsRemoteMsnServer() ? m_hRegMachineKey : HKEY_LOCAL_MACHINE; return RegCreateKeyEx( hRoot, m_szDebugAsyncTrace, 0, NULL, REG_OPTION_NON_VOLATILE, KEY_READ|KEY_WRITE, NULL, &m_hRegKey, &dwDisposition ); } BOOL CRegTraceApp::CloseTraceRegKey() { BOOL bRC = RegCloseKey( m_hRegKey ) == ERROR_SUCCESS; if ( IsRemoteMsnServer() && m_hRegMachineKey != NULL ) { bRC == RegCloseKey( m_hRegMachineKey ) == ERROR_SUCCESS && bRC; } return bRC; } BOOL CRegTraceApp::GetTraceRegDword( LPTSTR pszValue, LPDWORD pdw ) { DWORD cbData = sizeof( DWORD ); DWORD dwType = REG_DWORD; return RegQueryValueEx(m_hRegKey, pszValue, NULL, &dwType, (LPBYTE)pdw, &cbData ) == ERROR_SUCCESS && dwType == REG_DWORD; } BOOL CRegTraceApp::GetTraceRegString( LPTSTR pszValue, CString& sz ) { DWORD dwType = REG_DWORD; char szTemp[MAX_PATH+1]; DWORD cbData = sizeof(szTemp); BOOL bRC; bRC = RegQueryValueEx( m_hRegKey, pszValue, NULL, &dwType, (LPBYTE)szTemp, &cbData ) == ERROR_SUCCESS && dwType == REG_SZ; if ( bRC ) { sz = szTemp; } return bRC; } BOOL CRegTraceApp::SetTraceRegDword( LPTSTR pszValue, DWORD dwData ) { return RegSetValueEx( m_hRegKey, pszValue, NULL, REG_DWORD, (LPBYTE)&dwData, sizeof( DWORD ) ) == ERROR_SUCCESS; } BOOL CRegTraceApp::SetTraceRegString( LPTSTR pszValue, CString& sz ) { return RegSetValueEx( m_hRegKey, pszValue, NULL, REG_SZ, (LPBYTE)(LPCTSTR)sz, sz.GetLength()+1 ) == ERROR_SUCCESS; }