HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
UT_NTRegKey.h
Go to the documentation of this file.
1 /*
2  * PROPRIETARY INFORMATION. This software is proprietary to
3  * Side Effects Software Inc., and is not to be reproduced,
4  * transmitted, or disclosed in any way without written permission.
5  *
6  * NAME: UT_NTRegKey.h (UT Library, C++)
7  *
8  * COMMENTS:
9  *
10  */
11 
12 #ifndef __UT_NTREGKEY_H_INCLUDED__
13 #define __UT_NTREGKEY_H_INCLUDED__
14 
15 #ifdef _WIN32
16 
17 #include "UT_API.h"
18 #include "UT_WorkBuffer.h"
19 
20 #include <stddef.h>
21 #include <windows.h>
22 
23 
24 class UT_NTRegKey
25 {
26 public:
27  UT_NTRegKey()
28  : myHandle(NULL)
29  {
30  }
31  ~UT_NTRegKey()
32  {
33  closeIfOpen();
34  }
35 
36  bool open(HKEY key_parent, const char *reg_path)
37  {
38  closeIfOpen();
39 
40  if (RegOpenKeyEx(key_parent, reg_path, 0, KEY_QUERY_VALUE, &myHandle)
41  == ERROR_SUCCESS)
42  return true;
43 
44  myHandle = NULL;
45  return false;
46  }
47 
48  bool open(HKEY key_parent, const UT_WorkBuffer &reg_path)
49  {
50  return open(key_parent, reg_path.buffer());
51  }
52 
53  void closeIfOpen()
54  {
55  if (myHandle)
56  {
57  RegCloseKey(myHandle);
58  myHandle = NULL;
59  }
60  }
61 
62  bool getValue(const char *key_name, UT_WorkBuffer &value)
63  {
64  value.clear();
65 
66  if (!myHandle)
67  return false;
68 
69  DWORD len;
70  if (RegQueryValueEx(myHandle, key_name, 0, 0, NULL, &len)
71  != ERROR_SUCCESS)
72  return false;
73 
74  bool ok = (RegQueryValueEx(myHandle, key_name, 0, 0,
75  (LPBYTE)value.lock(0, len), &len)
76  == ERROR_SUCCESS);
77  value.release(true);
78 
79  return (ok && value.isstring());
80  }
81 
82 private:
83  HKEY myHandle;
84 };
85 
86 #endif // _WIN32
87 
88 #endif // __UT_NTREGKEY_H_INCLUDED__
SYS_FORCE_INLINE const char * buffer() const
char * lock(exint offset=0, exint reserve_bytes=0)
virtual int open(float queuesize)
GLsizei const GLfloat * value
Definition: glcorearb.h:823
SYS_FORCE_INLINE bool isstring() const
void release(int recomputeLength=0)
SYS_FORCE_INLINE void clear()