|
From: Lorenzo <co...@in...> - 2001-06-21 09:28:01
|
This is an example for set key in registry:
#include <windows.h>
int main(int argc, char *argv[])
{
HKEY hKey;
DWORD dwDisposition;
unsigned char *szBuf = (unsigned char *)strdup("lorenzo");
if (RegCreateKeyEx(HKEY_CURRENT_USER, "test", 0, "REG_SZ",
REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, 0, &hKey, &dwDisposition) !=
ERROR_SUCCESS)
return 1;
if (RegSetValueEx(hKey, "string", 0, REG_SZ, szBuf,
strlen((char*)szBuf)) != ERROR_SUCCESS)
return 1;
RegCloseKey(hKey);
return 0;
}
This program open or create if not exist the key "test" in key
HKEY_CURRENT_USER and create string value "string" with value "lorenzo".
This is an example for get key in registry:
#include <windows.h>
int main(int argc, char *argv[])
{
HKEY hKey;
DWORD dwType;
DWORD dwLen;
unsigned char szBuf[255] = {0};
if (RegOpenKeyEx(HKEY_CURRENT_USER, "test", 0, KEY_ALL_ACCESS, &hKey)
!= ERROR_SUCCESS)
return 1;
if (RegQueryValueEx(hKey, "string", 0, &dwType, szBuf, &dwLen) !=
ERROR_SUCCESS)
return 1;
RegCloseKey(hKey);
return 0;
}
This program open the existing key "test" and read value from string value
"string", copy it into szBuf, the size of string is stored into dwLen and
the type of value key is stored into dwType.
I hope this can help you.
----------------------------------------------------------------------------
---
If debugging is the process of removing bugs,
then programming must be the process of putting them in.
----------------------------------------------------------------------------
---
|