Jul 5, 2018 at 6:03pm UTC
Is this page helpful?
YES NO
EDIT: Taken from code I wrote back in the 90s
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
bool ntreg::Reg::Iterator::operator ++(int )
{
if (iteration_complete)
return false ;
reinitialized = false ;
DWORD name_sz = sizeof (name.size());
DWORD classname_sz = sizeof (classname.size());
LONG ret = ::RegEnumKeyEx(
reg.GetKey(),
cnt++,
name, &name_sz,
0,
classname, &classname_sz,
&last_write_time);
if (ret != NO_ERROR)
{
iteration_complete = true ;
return false ;
}
return true ;
}
Last edited on Jul 5, 2018 at 6:11pm UTC
Jul 5, 2018 at 6:29pm UTC
Oh, you can bet I left my feedback.
My version looks like this:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
std::vector<std::wstring> enum_subkeys(HKEY key){
std::vector<std::wstring> ret;
for (DWORD i = 0; ; i++){
std::wstring name(256, 0);
while (true ){
auto size = (DWORD)name.size();
auto result = RegEnumKeyExW(key, i, &name[0], &size, nullptr , nullptr , nullptr , nullptr );
if (result == ERROR_SUCCESS){
name.resize(size);
ret.emplace_back(std::move(name));
break ;
}
if (result == ERROR_NO_MORE_ITEMS)
return ret;
if (result == ERROR_MORE_DATA){
name.resize(name.size() * 2);
continue ;
}
std::stringstream stream;
stream << "RegEnumKeyW() failed with error " ;
error_to_stream(stream, result);
throw std::runtime_error(stream.str());
}
}
assert(false );
return ret;
}
Last edited on Jul 5, 2018 at 6:35pm UTC
Jul 6, 2018 at 6:14am UTC
That'll do it :)
No one seems to use Class Name, but back in the day we weren't to know that.
Does the compiler warn about mixing DWORD and size_t?
Jul 6, 2018 at 1:44pm UTC
Only if they're different types.