/*********************************************************************** * drvSetDefaultCommConfigW (SERIALUI.@) * * Used by Win98 KERNEL to set the default config for a COMM port * FIXME: uses the wrong registry key... should use a digit, not * the comm port name. */ BOOL WINAPI drvSetDefaultCommConfigW( LPCWSTR lpszDevice, LPCOMMCONFIG lpCommConfig, DWORD dwSize) { HKEY hKeyReg=0, hKeyPort=0; WCHAR szKeyName[100]; DWORD r,dwDCBSize; static const WCHAR fmt[] = {'%','s','\\','%','s',0 }; TRACE("%p %p %lx\n",lpszDevice,lpCommConfig,dwSize); if(!lpCommConfig) return FALSE; if(dwSize < sizeof (COMMCONFIG)) return FALSE; r = RegConnectRegistryW(NULL, HKEY_LOCAL_MACHINE, &hKeyReg); if(r != ERROR_SUCCESS) return FALSE; snprintfW(szKeyName, sizeof(szKeyName)/sizeof(WCHAR), fmt, lpszCommKey ,lpszDevice); r = RegCreateKeyW(hKeyReg, szKeyName, &hKeyPort); if(r == ERROR_SUCCESS) { dwDCBSize = sizeof (DCB); r = RegSetValueExW( hKeyPort, lpszDCB, 0, REG_BINARY, (LPBYTE)&lpCommConfig->dcb,dwDCBSize); TRACE("write key r=%ld\n",r); RegCloseKey(hKeyPort); } RegCloseKey(hKeyReg); return (r==ERROR_SUCCESS); }
BOOL My_RegConnectRegistryW() { LPCWSTR lpMachineName=NULL; HKEY hKey=NULL; PHKEY phkResult=NULL; LONG returnVal_Real = NULL; LONG returnVal_Intercepted = NULL; DWORD error_Real = 0; DWORD error_Intercepted = 0; __try{ disableInterception(); returnVal_Real = RegConnectRegistryW (lpMachineName,hKey,phkResult); error_Real = GetLastError(); enableInterception(); returnVal_Intercepted = RegConnectRegistryW (lpMachineName,hKey,phkResult); error_Intercepted = GetLastError(); }__except(puts("in filter"), 1){puts("exception caught");} return ((returnVal_Real == returnVal_Intercepted) && (error_Real == error_Intercepted)); }
PDH_STATUS ConnectMachine ( PPERF_MACHINE pThisMachine ) { LONGLONG llCurrentTime; PDH_STATUS pdhStatus; LONG lStatus; // only one thread at a time can try to connect to a machine. WAIT_FOR_AND_LOCK_MUTEX(pThisMachine->hMutex); // get the current time GetLocalFileTime (&llCurrentTime); if (pThisMachine->llRetryTime < llCurrentTime) { if (pThisMachine->llRetryTime != 0) { // connect to system's performance registry if (lstrcmpiW(pThisMachine->szName, szStaticLocalMachineName) == 0) { // this is the local machine so use the local reg key pThisMachine->hKeyPerformanceData = HKEY_PERFORMANCE_DATA; } else { __try { // close any open keys if (pThisMachine->hKeyPerformanceData != NULL) { RegCloseKey (pThisMachine->hKeyPerformanceData); pThisMachine->hKeyPerformanceData = NULL; } } __except (EXCEPTION_EXECUTE_HANDLER) { lStatus = GetExceptionCode(); } // now try to connect __try { // this can generate exceptions in some error cases // so trap them here and continue // remote machine so try to connect to it. lStatus = RegConnectRegistryW ( pThisMachine->szName, HKEY_PERFORMANCE_DATA, &pThisMachine->hKeyPerformanceData); } __except (EXCEPTION_EXECUTE_HANDLER) { lStatus = GetExceptionCode(); } if (lStatus != ERROR_SUCCESS) { pThisMachine->hKeyPerformanceData = NULL; } } if (pThisMachine->hKeyPerformanceData != NULL) { // successfully connected to computer's registry, so // get the performance names from that computer and cache them if (pThisMachine->szPerfStrings != NULL) { // reload the perf strings, incase new ones have been // installed G_FREE (pThisMachine->szPerfStrings); pThisMachine->szPerfStrings = NULL; } pThisMachine->szPerfStrings = BuildNameTable ( (pThisMachine->hKeyPerformanceData == HKEY_PERFORMANCE_DATA ? NULL : pThisMachine->szName), NULL, &pThisMachine->dwLastPerfString); if (pThisMachine->szPerfStrings != NULL) { pdhStatus = ERROR_SUCCESS; pThisMachine->dwStatus = ERROR_SUCCESS; } else { // unable to read system counter name strings pdhStatus = PDH_CANNOT_READ_NAME_STRINGS; pThisMachine->dwStatus = PDH_CSTATUS_NO_MACHINE; } } else { // unable to connect to remote machine pdhStatus = PDH_CANNOT_CONNECT_MACHINE; pThisMachine->dwStatus = PDH_CSTATUS_NO_MACHINE; } } else { // already connected // (note: is there a way to test this?) pdhStatus = ERROR_SUCCESS; pThisMachine->dwStatus = ERROR_SUCCESS; } if (pdhStatus != ERROR_SUCCESS) { // this attempt didn't work so reset retry counter to // wait some more for the machine to come back up. pThisMachine->llRetryTime = llCurrentTime + RETRY_TIME_INTERVAL; } else { // clear the retry counter to allow function calls pThisMachine->llRetryTime = 0; } } else {
/*********************************************************************** * drvGetDefaultCommConfigW (SERIALUI.@) * * Used by Win9x KERNEL to get the default config for a COMM port * FIXME: uses the wrong registry key... should use a digit, not * the comm port name. */ BOOL WINAPI drvGetDefaultCommConfigW( LPCWSTR lpszDevice, LPCOMMCONFIG lpCommConfig, LPDWORD lpdwSize) { HKEY hKeyReg, hKeyPort; WCHAR szKeyName[100]; DWORD r,dwSize,dwType; static const WCHAR fmt[] = {'%','s','\\','%','s',0 }; TRACE("%p %p %p\n",lpszDevice,lpCommConfig,lpdwSize); if(!lpCommConfig) return FALSE; if(!lpdwSize) return FALSE; if(*lpdwSize < sizeof (COMMCONFIG)) return FALSE; *lpdwSize = sizeof (COMMCONFIG); memset(lpCommConfig, 0 , sizeof (COMMCONFIG)); lpCommConfig->dwSize = sizeof (COMMCONFIG); lpCommConfig->wVersion = 1; r = RegConnectRegistryW(NULL, HKEY_LOCAL_MACHINE, &hKeyReg); if(r != ERROR_SUCCESS) return FALSE; snprintfW(szKeyName, sizeof(szKeyName)/sizeof(WCHAR), fmt, lpszCommKey ,lpszDevice); r = RegOpenKeyW(hKeyReg, szKeyName, &hKeyPort); if(r == ERROR_SUCCESS) { dwSize = sizeof (DCB); dwType = 0; r = RegQueryValueExW( hKeyPort, lpszDCB, NULL, &dwType, (LPBYTE)&lpCommConfig->dcb, &dwSize); if ((r==ERROR_SUCCESS) && (dwType != REG_BINARY)) r = 1; if ((r==ERROR_SUCCESS) && (dwSize != sizeof(DCB))) r = 1; RegCloseKey(hKeyPort); } else { /* FIXME: default to a hardcoded commconfig */ lpCommConfig->dcb.DCBlength = sizeof(DCB); lpCommConfig->dcb.BaudRate = 9600; lpCommConfig->dcb.fBinary = TRUE; lpCommConfig->dcb.fParity = FALSE; lpCommConfig->dcb.ByteSize = 8; lpCommConfig->dcb.Parity = NOPARITY; lpCommConfig->dcb.StopBits = ONESTOPBIT; return TRUE; } RegCloseKey(hKeyReg); return (r==ERROR_SUCCESS); }
/*********************************************************************** * drvGetDefaultCommConfigW (SERIALUI.@) * * Used by Win9x KERNEL to get the default config for a COMM port * FIXME: uses the wrong registry key... should use a digit, not * the comm port name. */ DWORD WINAPI drvGetDefaultCommConfigW( LPCWSTR lpszDevice, LPCOMMCONFIG lpCommConfig, LPDWORD lpdwSize) { HKEY hKeyReg, hKeyPort; WCHAR szKeyName[100]; DWORD r,dwSize,dwType; static const WCHAR fmt[] = {'%','s','\\','%','s',0 }; TRACE("(%s, %p, %p) *lpdwSize: %u\n", debugstr_w(lpszDevice), lpCommConfig, lpdwSize, lpdwSize ? *lpdwSize : 0); if ((!lpszDevice) || (!lpCommConfig) || (!lpdwSize)) { return ERROR_INVALID_PARAMETER; } if (*lpdwSize < sizeof (COMMCONFIG)) { *lpdwSize = sizeof (COMMCONFIG); return ERROR_INSUFFICIENT_BUFFER; } /* only "com1" - "com9" is allowed */ r = sizeof(comW) / sizeof(WCHAR); /* len of "com\0" */ lstrcpynW(szKeyName, lpszDevice, r); /* simulate a lstrcmpnW */ r--; if( lstrcmpiW(szKeyName, comW) || (lpszDevice[r] < '1') || (lpszDevice[r] > '9') || lpszDevice[r+1]) { return ERROR_BADKEY; } *lpdwSize = sizeof (COMMCONFIG); memset(lpCommConfig, 0 , sizeof (COMMCONFIG)); lpCommConfig->dwSize = sizeof (COMMCONFIG); lpCommConfig->wVersion = 1; lpCommConfig->dwProviderSubType = PST_RS232; r = RegConnectRegistryW(NULL, HKEY_LOCAL_MACHINE, &hKeyReg); if(r != ERROR_SUCCESS) return r; snprintfW(szKeyName, sizeof(szKeyName)/sizeof(WCHAR), fmt, lpszCommKey ,lpszDevice); r = RegOpenKeyW(hKeyReg, szKeyName, &hKeyPort); if(r == ERROR_SUCCESS) { dwSize = sizeof (DCB); dwType = 0; r = RegQueryValueExW( hKeyPort, lpszDCB, NULL, &dwType, (LPBYTE)&lpCommConfig->dcb, &dwSize); RegCloseKey(hKeyPort); if ((r!=ERROR_SUCCESS) || (dwType != REG_BINARY) || (dwSize != sizeof(DCB))) { RegCloseKey(hKeyReg); return ERROR_INVALID_PARAMETER; } } else { /* FIXME: default to a hardcoded commconfig */ lpCommConfig->dcb.DCBlength = sizeof(DCB); lpCommConfig->dcb.BaudRate = 9600; lpCommConfig->dcb.fBinary = TRUE; lpCommConfig->dcb.fParity = FALSE; lpCommConfig->dcb.ByteSize = 8; lpCommConfig->dcb.Parity = NOPARITY; lpCommConfig->dcb.StopBits = ONESTOPBIT; return ERROR_SUCCESS; } RegCloseKey(hKeyReg); return r; }