MCPcopy Create free account
hub / github.com/KDE/kdiff3 / getRegistryKeyString

Method getRegistryKeyString

diff_ext_for_kdiff3/server.cpp:47–94  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

45#endif
46
47tstring SERVER::getRegistryKeyString( const tstring& subKey, const tstring& value, bool isUserKey /*= true*/ )
48{
49 tstring keyName = m_registryBaseName;
50 if (!subKey.empty())
51 keyName += TEXT("\\")+subKey;
52
53 HKEY key;
54 HKEY baseKey = isUserKey ? HKEY_CURRENT_USER : HKEY_LOCAL_MACHINE;
55 tstring result;
56 for(;;)
57 {
58 if( RegOpenKeyEx( baseKey, keyName.c_str(), 0, KEY_READ | KEY_WOW64_64KEY, &key ) == ERROR_SUCCESS )
59 {
60 DWORD neededSizeInBytes = 0;
61 if (RegQueryValueEx(key, value.c_str(), nullptr, nullptr, nullptr, &neededSizeInBytes) == ERROR_SUCCESS)
62 {
63 DWORD length = neededSizeInBytes / sizeof( TCHAR );
64 result.resize( length );
65 if ( RegQueryValueEx( key, value.c_str(), nullptr, nullptr, (LPBYTE)&result[0], &neededSizeInBytes ) == ERROR_SUCCESS)
66 {
67 //Everything is ok, but we want to cut off the terminating 0-character
68 result.resize( length - 1 );
69 RegCloseKey(key);
70 return result;
71 }
72 else
73 {
74 result.resize(0);
75 }
76 }
77
78 RegCloseKey(key);
79 }
80 if (baseKey==HKEY_LOCAL_MACHINE)
81 break;
82 baseKey = HKEY_LOCAL_MACHINE;
83 }
84
85 // Error
86 {
87 LPTSTR message;
88 FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM, nullptr,
89 GetLastError(), MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPTSTR) &message, 0, nullptr);
90 ERRORLOG( (tstring(TEXT("RegOpenKeyEx: ")+keyName+TEXT("->")+value) + TEXT(": ")) + message ); \
91 LocalFree(message);
92 }
93 return result;
94}
95
96
97STDAPI

Callers 1

diffMethod · 0.80

Calls

no outgoing calls

Tested by

no test coverage detected