c++ - RegQueryValueExW only brings back one value from registry -
i querying registry on windows ce. want pull dhcpdns value tcpip area of registry, works.
what happens though, however, if there 2 values - displayed "x.x.x.x" "x.x.x.x"
in ce registry editor - brings 1 of them. sure silly mistake unsure why happening.
here code using
std::string isapiconfig::gettcpipregsetting(const std::wstring ®entryname) { hkey hkey = 0; hkey root = hkey_local_machine; long retval = 0; wchar_t buffer[3000]; dword buffersize = 0; dword datatype = 0; std::string datastring = ""; //open ip regkey retval = regopenkeyexw(root, l"comm\\pci\\fetce6b1\\parms\\tcpip", 0, 0, &hkey); //pull out info need memset(buffer, 0, sizeof(buffer)); buffersize = sizeof(buffer); retval = regqueryvalueexw(hkey, regentryname.c_str(), 0, &datatype, reinterpret_cast<lpbyte>(buffer), &buffersize); unicode::unicodetoansi(buffer, datastring); return datastring; } void unicodetoansi(const std::wstring &widestring, std::string &ansistring){ std::wostringstream converter; std::ostringstream converted; std::wstring::const_iterator loop; for(loop = widestring.begin(); loop != widestring.end(); ++loop){ converted << converter.narrow((*loop)); } ansistring = converted.str(); }
the value multi_sz, in format:
{data}\0{data}\0\0
i don't know unicode::unicodetoansi does, it's looking first null terminator , stopping there. have parse past single nulls until hit double-null.
edit
you have update code - interfaces. right you're trying returns string multi_sz which, definition, means multiple strings. want returns string[] (though i'd opt use couple output parameters - 1 that's array pointer , other element count).
you need loop through data came regquery call, maybe (off top of head, not tested or compiled):
tchar *p = buffer; if(buffersize > 0) { { unicode::unicodetoansi(p, datastring); // datastring - store in array or whatever p+= _tcslen(p); } while((p-buffer) < buffersize) }
Comments
Post a Comment