LONG GetBoolRegKey(HKEY hKey, const std::wstring &strValueName, bool &bValue, bool bDefaultValue) { DWORD nDefValue((bDefaultValue) ? 1 : 0); DWORD nResult(nDefValue); LONG nError = GetDWORDRegKey(hKey, strValueName.c_str(), nResult, nDefValue); if (ERROR_SUCCESS == nError) { bValue = (nResult != 0) ? true : false; } return nError; }
LONG ServiceRegistry::GetBoolRegKey(HKEY hKey, String strValueName, bool &bValue, bool bDefaultValue) { DWORD nDefValue((bDefaultValue) ? 1 : 0); DWORD nResult(nDefValue); LONG nError = GetDWORDRegKey(hKey, strValueName.lpcwstr(), nResult, nDefValue); if (ERROR_SUCCESS == nError) { bValue = (nResult != 0) ? true : false; } return nError; }
LONG ServiceRegistry::GetDWORDRegKey(HKEY hKey, String strValueName, DWORD &nValue, DWORD nDefaultValue) { nValue = nDefaultValue; DWORD dwBufferSize(sizeof(DWORD)); DWORD nResult(0); LONG nError = ::RegQueryValueExW(hKey,strValueName.lpcwstr(),0, NULL,reinterpret_cast<LPBYTE>(&nResult),&dwBufferSize); if (ERROR_SUCCESS == nError) { nValue = nResult; } return nError; }
LONG WindowsRegistryTools::GetDWORDRegKey(HKEY hKey, const std::wstring &strValueName, DWORD &nValue, DWORD nDefaultValue) { nValue = nDefaultValue; DWORD dwBufferSize(sizeof(DWORD)); DWORD nResult(0); LONG nError = ::RegQueryValueExW(hKey, strValueName.c_str(), 0, NULL, reinterpret_cast<LPBYTE>(&nResult), &dwBufferSize); if (ERROR_SUCCESS == nError) { nValue = nResult; } return nError; }
void cDebugFile::Output(string sKeyList /* = */, eOutPut eOutType /* = All */) { std::vector<string> vecKey; ParseName(vecKey, sKeyList); ostringstream osFile; int64 nResult(0); // >0增加 <0减少 =0不变 for (size_t i = 0; i < m_keyPos; ++i) { stKeyInfo& info = m_vecKey[i]; if (!vecKey.empty() && find(vecKey.begin(), vecKey.end(), info.key) == vecKey.end()) { continue; } switch (info.type){ case v_uint8:{ nResult = int16(*(uint8*)info.pObj) - int16(*(uint8*)info.pOld); //可为-255 if (OnResult(eOutType, nResult, info.key, osFile)) { osFile << " = " << *(uint8*)info.pObj << "(" << *(uint8*)info.pOld << ")" << ";\r\n"; } }break; case v_uint16:{ nResult = int32(*(uint16*)info.pObj) - int32(*(uint16*)info.pOld); if (OnResult(eOutType, nResult, info.key, osFile)) { osFile << " = " << *(uint16*)info.pObj << "(" << *(uint16*)info.pOld << ")" << ";\r\n"; } }break; case v_uint32:{ nResult = int64(*(uint32*)info.pObj) - int64(*(uint32*)info.pOld); if (OnResult(eOutType, nResult, info.key, osFile)) { osFile << " = " << *(uint32*)info.pObj << "(" << *(uint32*)info.pOld << ")" << ";\r\n"; } }break; case v_uint64:{ nResult = (*(int64*)info.pObj) - (*(int64*)info.pOld); if (OnResult(eOutType, nResult, info.key, osFile)) { osFile << " = " << *(int64*)info.pObj << "(" << *(int64*)info.pOld << ")" << ";\r\n"; } }break; case v_int8:{ nResult = int16(*(int8*)info.pObj) - int16(*(int8*)info.pOld); if (OnResult(eOutType, nResult, info.key, osFile)) { osFile << " = " << *(int8*)info.pObj << "(" << *(int8*)info.pOld << ")" << ";\r\n"; } } break; case v_int16:{ nResult = int32(*(int16*)info.pObj) - int32(*(int16*)info.pOld); if (OnResult(eOutType, nResult, info.key, osFile)) { osFile << " = " << *(int16*)info.pObj << "(" << *(int16*)info.pOld << ")" << ";\r\n"; } }break; case v_int32:{ nResult = int64(*(int32*)info.pObj) - int64(*(int32*)info.pOld); if (OnResult(eOutType, nResult, info.key, osFile)) { osFile << " = " << *(int32*)info.pObj << "(" << *(int32*)info.pOld << ")" << ";\r\n"; } }break; case v_int64:{ nResult = (*(int64*)info.pObj) - (*(int64*)info.pOld); if (OnResult(eOutType, nResult, info.key, osFile)) { osFile << " = " << *(int64*)info.pObj << "(" << *(int64*)info.pOld << ")" << ";\r\n"; } }break; case v_float:{ float dif = (*(float*)info.pObj) - (*(float*)info.pOld); if (OnResult(eOutType, dif == 0 ? 0 : (dif>0 ? 1 : -1), info.key, osFile)) { osFile << " = " << *(float*)info.pObj << "(" << *(float*)info.pOld << ")" << ";\r\n"; } }break; case v_double:{ double dif = (*(double*)info.pObj) - (*(double*)info.pOld); if (OnResult(eOutType, dif == 0 ? 0 : (dif>0 ? 1 : -1), info.key, osFile)) { osFile << " = " << *(double*)info.pObj << "(" << *(double*)info.pOld << ")" << ";\r\n"; } }break; case v_string:{ nResult = strcmp(info.pObj, info.pOld); if (OnResult(eOutType, nResult, info.key, osFile)) { osFile << " = " << info.pObj << "(" << info.pOld << ")" << ";\r\n"; } }break; default:{ nResult = int64(*(int32*)info.pObj) - int64(*(int32*)info.pOld); if (OnResult(eOutType, nResult, info.key, osFile)) { osFile << " = " << *(int32*)info.pObj << "(" << *(int32*)info.pOld << ")" << ";\r\n"; } }break; } } osFile << "\r\n"; WriteToFile(m_sFileName, osFile); }