c++ - I use CRegKey to open some, but this m_hKey != 0 -
i want jdk path registry, path is:
hkey_local_machine\\software\\javasoft\\java development kit\\1.8
when use:
cregkey.open(hkey_local_machine, l"software\\javasoft\\java development kit\\1.8")
it throws expression m_hkey != 0. what's happening ? how fix bug?
here code:
// java environment variable install path cregkey key; wchar_t javahome[40]; ulong szjavahome = 40; bool rest = key.open(hkey_local_machine, l"software\\javasoft\\java development kit\\1.8"); if (key.m_hkey == 0) messagebox(l"11"); rest = key.querystringvalue(l"javahome", javahome, &szjavahome);
you cannot use cregkey
variable key
after trying open
it, without checking return value of it.
auto retopenkey = key.open(...); //long not bool if (error_success == retopenkey) { //ok stuff key } else auto err = getlasterror();
system error codes , / or formatmessage
you can in implementation of function, , debug in there, inline in header:
inline long cregkey::open( _in_ hkey hkeyparent, _in_opt_z_ lpctstr lpszkeyname, _in_ regsam samdesired) throw() { atlassume(hkeyparent != null); hkey hkey = null; long lres = m_ptm != null ? m_ptm->regopenkeyex(hkeyparent, lpszkeyname, 0, samdesired, &hkey) : regopenkeyex(hkeyparent, lpszkeyname, 0, samdesired, &hkey); if (lres == error_success) { lres = close(); atlassert(lres == error_success); m_hkey = hkey; #if winver >= 0x0501 m_samwow64 = samdesired & (key_wow64_32key | key_wow64_64key); #endif } return lres; }
Comments
Post a Comment