14 #include "openwidedll.h"
15 //#include "openwideres.h"
16 #include "owSharedUtil.h"
20 void dbg(char *szError
, ...)
25 va_start(vl
, szError
);
26 vsnprintf(szBuff
, 256, szError
, vl
); // print error message to string
27 OutputDebugString(szBuff
);
34 char * getDlgItemText(HWND hwnd
, UINT uID
)
36 HWND hwCtl
= GetDlgItem(hwnd
, uID
);
37 if(! IsWindow(hwCtl
) )
39 int len
= GetWindowTextLength(hwCtl
);
42 char * buf
= malloc(len
+1);
45 len
= GetWindowText(hwCtl
, buf
, len
+1);
55 DWORD
GetDllVersion(LPCTSTR lpszDllName
)
59 char szDll
[MAX_PATH
+1];
60 /* For security purposes, LoadLibrary should be provided with a
61 fully-qualified path to the DLL. The lpszDllName variable should be
62 tested to ensure that it is a fully qualified path before it is used. */
63 if( !PathSearchAndQualify(lpszDllName
, szDll
, MAX_PATH
) )
65 hinstDll
= LoadLibrary(szDll
);
69 DLLGETVERSIONPROC pDllGetVersion
;
70 pDllGetVersion
= (DLLGETVERSIONPROC
) GetProcAddress(hinstDll
, "DllGetVersion");
72 /* Because some DLLs might not implement this function, you
73 must test for it explicitly. Depending on the particular
74 DLL, the lack of a DllGetVersion function can be a useful
75 indicator of the version. */
82 ZeroMemory(&dvi
, sizeof(dvi
));
83 dvi
.cbSize
= sizeof(dvi
);
85 hr
= (*pDllGetVersion
)(&dvi
);
89 dwVersion
= PACKVERSION(dvi
.dwMajorVersion
, dvi
.dwMinorVersion
);
93 FreeLibrary(hinstDll
);
101 return GetDllVersion("Shell32.dll") >= PACKVERSION(6,00);
108 void regCloseKey(HKEY hk
)
114 HKEY
regCreateKey(HKEY hkParent
, const char *szSubKey
){
117 res
= RegCreateKeyEx(hkParent
, szSubKey
, 0L, NULL
, REG_OPTION_NON_VOLATILE
,
118 KEY_READ
| KEY_WRITE
, NULL
, &hk
, NULL
);
119 return ( res
== ERROR_SUCCESS
) ? hk
: NULL
;
123 int regDeleteKey(HKEY hkParent
, const char *szSubKey
)
126 rv
= ( SHDeleteKey(hkParent
, szSubKey
) == ERROR_SUCCESS
);
131 int regEnumValues(HKEY hkRoot
, RegValEnumProc fp
, LPVOID param
)
133 DWORD ccBuf
= regGetMaxValueNameLength(hkRoot
, NULL
);
135 char *buf
= malloc(ccBuf
* sizeof(char));
146 rCode
= RegEnumValue(hkRoot
, i
, buf
, &tmp
, NULL
, &dwType
, NULL
, NULL
);
147 if(rCode
!= ERROR_SUCCESS
)
149 if(rCode
!= ERROR_NO_MORE_ITEMS
)
150 Warn("Error code %d : \r\n%s\r\non calling RegEnumValue()", rCode
, geterrmsg() );
153 res
= fp(hkRoot
, buf
, dwType
, param
);
163 DWORD
regGetDWORD(HKEY hkRoot
, const char *szValue
, int *pSuccess
){
164 DWORD dwType
, dwSize
= 0;
170 res
= RegQueryValueEx(hkRoot
, szValue
, NULL
, &dwType
, NULL
, &dwSize
);
171 if( res
== ERROR_SUCCESS
172 && (dwType
== REG_DWORD
|| REG_DWORD_LITTLE_ENDIAN
)
173 && dwSize
== sizeof(dword
))
175 res
= RegQueryValueEx(hkRoot
, szValue
, NULL
, NULL
, (BYTE
*)&dword
, &dwSize
);
176 if( res
== ERROR_SUCCESS
&& pSuccess
)
183 int regGetMaxValueNameLength(HKEY hk
, LPDWORD pValueDataLen
)
185 DWORD dwNLen
, dwDLen
;
188 pValueDataLen
= &dwDLen
;
191 hk
, NULL
, NULL
, NULL
, NULL
,
192 NULL
, NULL
, NULL
, &dwNLen
, pValueDataLen
,
193 NULL
, NULL
) == ERROR_SUCCESS
)
199 HKEY
regOpenKey(HKEY hkParent
, const char *szSubKey
){
203 if(!szSubKey
) return NULL
;
204 res
= RegOpenKeyEx(hkParent
, szSubKey
, 0L, KEY_READ
| KEY_WRITE
, &hk
);
205 return ( res
== ERROR_SUCCESS
) ? hk
: NULL
;
209 BYTE
*regReadBinaryData(HKEY hkRoot
, const char *szValueName
){
210 DWORD dwType
, dwSize
= 0;
212 res
= RegQueryValueEx(hkRoot
, szValueName
, NULL
, &dwType
, NULL
, &dwSize
);
213 if( res
== ERROR_SUCCESS
&& dwType
== REG_BINARY
&& dwSize
> 0)
215 BYTE
* buf
= malloc(dwSize
);
218 res
= RegQueryValueEx(hkRoot
, szValueName
, NULL
, NULL
, buf
, &dwSize
);
219 if( res
== ERROR_SUCCESS
)
226 DWORD
regReadDWORD(HKEY hkRoot
, const char *szValueName
, int *pSuccess
)
229 DWORD dwType
, dwSize
= 0;
234 res
= RegQueryValueEx(hkRoot
, szValueName
, NULL
, &dwType
, NULL
, &dwSize
);
235 if( res
== ERROR_SUCCESS
&& (dwType
== REG_DWORD
|| REG_DWORD_LITTLE_ENDIAN
) && dwSize
== sizeof(DWORD
) )
237 res
= RegQueryValueEx(hkRoot
, szValueName
, NULL
, NULL
, (BYTE
*)&dword
, &dwSize
);
238 if( res
== ERROR_SUCCESS
&& pSuccess
)
245 char *regReadSZ(HKEY hk
, const char *szValueName
){
247 DWORD dwType
, dwSize
= 0L;
249 res
= RegQueryValueEx(hk
, szValueName
, NULL
, &dwType
, NULL
, &dwSize
);
250 if( res
== ERROR_SUCCESS
)
252 if(dwSize
> 1 && (dwType
== REG_SZ
|| dwType
== REG_EXPAND_SZ
) )
254 char * szData
= malloc(dwSize
);
255 res
= RegQueryValueEx(hk
, szValueName
, NULL
, &dwType
, (BYTE
*)szData
, &dwSize
);
256 if(res
== ERROR_SUCCESS
)
264 int regWriteBinaryData(HKEY hkRoot
, const char *szValue
, BYTE
*buf
, int bufSize
){
266 res
= RegSetValueEx(hkRoot
, szValue
, 0L, REG_BINARY
, buf
, bufSize
);
267 return (res
== ERROR_SUCCESS
);
271 int regWriteDWORD(HKEY hkRoot
, const char *szValue
, DWORD dwData
){
273 res
= RegSetValueEx(hkRoot
, (LPCTSTR
)szValue
, 0L, REG_DWORD
,
276 return (res
== ERROR_SUCCESS
);
280 int regWriteSZ(HKEY hkRoot
, const char *szValueName
, const char *szData
){
285 res
= RegSetValueEx(hkRoot
, (LPCTSTR
)szValueName
, 0L, REG_SZ
,
288 return (res
== ERROR_SUCCESS
);
293 const char * geterrmsg(void)
295 static char szMsg
[256];
296 FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM
|
297 FORMAT_MESSAGE_IGNORE_INSERTS
,
300 MAKELANGID(LANG_NEUTRAL
, SUBLANG_DEFAULT
), // Default language
305 int len
= strlen(szMsg
) - 1;
306 if(len
< 0) return NULL
;
307 while( szMsg
[len
] == '\r' || szMsg
[len
] == '\n'){
316 void Warn(char *szError
, ...)
320 va_start(vl
, szError
);
321 _vsnprintf(szBuff
, 256, szError
, vl
); // print error message to string
322 OutputDebugString(szBuff
);
323 MessageBox(NULL
, szBuff
, "Error", MB_OK
); // show message