OpenCBM
registry.c
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU General Public License
4  * as published by the Free Software Foundation; either version
5  * 2 of the License, or (at your option) any later version.
6  *
7  * Copyright 2001-2004, 2007-2009 Spiro Trikaliotis
8  *
9 */
10 
20 #define DBG_USERMODE
21 
23 #ifndef DBG_PROGNAME
24  #define DBG_PROGNAME "OPENCBM-libmisc"
25 #endif // #ifndef DBG_PROGNAME
26 
27 #include <windows.h>
28 
29 #include "debug.h"
30 #include "cbmioctl.h"
31 
53 LONG
54 RegGetDWORD(IN HKEY RegKey, IN char *SubKey, OUT LPDWORD Value)
55 {
56  DWORD valueLen;
57  DWORD lpType;
58  DWORD value;
59  DWORD rc;
60 
61  FUNC_ENTER();
62 
63  FUNC_PARAM((DBG_PREFIX "Subkey = '%s'", SubKey));
64 
65  valueLen = sizeof(value);
66 
67  rc = RegQueryValueEx(RegKey, SubKey, NULL, &lpType, (LPBYTE)&value, &valueLen);
68 
69  DBG_ASSERT(valueLen == 4);
70 
71  if ((rc == ERROR_SUCCESS) && (valueLen == 4))
72  {
73  DBG_SUCCESS((DBG_PREFIX "RegGetDWORD"));
74  *Value = value;
75  }
76  else
77  {
78  DBG_ERROR((DBG_PREFIX "RegGetDWORD failed, returning -1"));
79  rc = -1;
80  }
81 
82  FUNC_LEAVE_INT(rc);
83 }
84 
85 
86 #if DBG
87 
88 #include "libmisc.h"
89 
96 void
97 cbm_get_debugging_flags(const char * ModuleName)
98 {
99  DWORD ret;
100  HKEY RegKey = 0;
101  char * dllDebugFlagsName = NULL;
102 
103  FUNC_ENTER();
104 
105  do {
106  if (ModuleName) {
107  dllDebugFlagsName = cbmlibmisc_strcat(CBM_REGKEY_SERVICE_DLL_DEBUGFLAGS "-", ModuleName);
108  }
109  else {
111  }
112 
113  // Open a registry key to HKLM<%REGKEY_SERVICE%>
114 
115  if (RegOpenKeyEx(HKEY_LOCAL_MACHINE,
117  0,
118  KEY_QUERY_VALUE,
119  &RegKey) )
120  {
121  DBG_WARN((DBG_PREFIX "RegOpenKeyEx() failed!"));
122  break;
123  }
124 
125  // now, get the number of the port to use
126 
127  if (RegGetDWORD(RegKey, CBM_REGKEY_SERVICE_DLL_DEBUGFLAGS, &ret) != ERROR_SUCCESS) {
129  " value, leaving default."));
130  }
131  else {
132  DbgFlags = ret;
133  }
134 
135  } while (0);
136 
137  // We're done, close the registry handle.
138 
139  RegCloseKey(RegKey);
140 
141  cbmlibmisc_strfree(dllDebugFlagsName);
142 
143  FUNC_LEAVE();
144 }
145 
146 #endif // #if DBG
void cbm_get_debugging_flags(const char *ModuleName)
Set the debugging flags.
Definition: registry.c:97
#define DBG_WARN(_xxx)
Definition: debug.h:395
#define FUNC_LEAVE_INT(_xxx)
Definition: debug.h:358
char * cbmlibmisc_strdup(const char *const OldString)
Duplicate a given string.
Definition: libstring.c:84
Define makros for debugging purposes.
unsigned long DbgFlags
void cbmlibmisc_strfree(const char *String)
Free a string.
Definition: libstring.c:172
#define CBM_REGKEY_SERVICE
Definition: cbmioctl.h:38
Define the IOCTL codes for the opencbm driver.
#define FUNC_LEAVE()
Definition: debug.h:349
LONG RegGetDWORD(IN HKEY RegKey, IN char *SubKey, OUT LPDWORD Value)
Get a DWORD value from the registry.
Definition: registry.c:54
#define DBG_ASSERT(_xxx)
Definition: debug.h:401
char * cbmlibmisc_strcat(const char *First, const char *Second)
Concatenate two strings.
Definition: libstring.c:202
#define DBG_ERROR(_xxx)
Definition: debug.h:397
#define DBG_SUCCESS(_xxx)
Definition: debug.h:393
#define FUNC_ENTER()
Definition: debug.h:347
#define FUNC_PARAM(_xxx)
Definition: debug.h:351
#define DBG_PREFIX
Definition: debug.h:320
#define CBM_REGKEY_SERVICE_DLL_DEBUGFLAGS
Definition: cbmioctl.h:56
Some functions for string handling.