April 01, 2003
Tech Tips
Tech Tips
Listing 2 Using the RegOpenKey() and RegOpenKeyEx() functions
#include <windows.h>
#if !defined(WIN32) && \
!defined(_WIN32)
#include <shellapi.h>
#endif /* Win16 */
#if defined(WIN32) || \
defined(_WIN32)
inline HKEY RegKeyDup(HKEY hkey, REGSAM samDesired = KEY_ALL_ACCESS)
{
HKEY hkeyDup;
LONG res = ::RegOpenKeyEx(hkey, NULL, 0, samDesired, &hkeyDup);
if(res != ERROR_SUCCESS)
{
hkeyDup = NULL;
}
return hkeyDup;
}
#else
inline HKEY RegKeyDup(HKEY hkey)
{
HKEY hkeyDup;
LONG res = ::RegOpenKey(hkey, NULL, &hkeyDup);
if(res != ERROR_SUCCESS)
{
hkeyDup = NULL;
}
return hkeyDup;
}
#endif /* Win32 */
int WINAPI WinMain( HINSTANCE hinst,
HINSTANCE hinstPrev,
LPSTR lpszCmdLine,
int nCmdShow)
{
HKEY hkey;
HKEY hkeyDup;
LONG lRes = ::RegOpenKey(HKEY_CLASSES_ROOT, ".cpp", &hkey);
if(lRes == ERROR_SUCCESS)
{
#if !defined(WIN32) && \
!defined(_WIN32)
char value[260];
#else
TCHAR value[260];
#endif /* Win16 */
LONG cbValue;
cbValue = sizeof(value);
::RegQueryValue(hkey, NULL, value, &cbValue);
::MessageBox(NULL, value, "Value from RegOpenKey()", MB_OK);
hkeyDup = RegKeyDup(hkey);
::RegCloseKey(hkey);
value[0] = '\0';
::RegQueryValue(hkeyDup, NULL, value, &cbValue);
::MessageBox(NULL, value, "Value from RegKeyDup()", MB_OK);
::RegCloseKey(hkeyDup);
}
return 0;
}
Previous Page |
1
|
2
|
3