|
From: Frazell T. <fr...@fl...> - 2001-01-03 04:11:37
|
I created one to do what i wanted done and get 31+ Errors they are =
listed after the source code can anyone see where i seemingly messed up
-----------------------------------------------SOURCE =
CODE---------------------------------------------------------------------=
----------------------------------
#include <stdio.h>
#include <winreg.h>
#include <windows.h>
#define REGDATA 1
int main()
{
//Tells user program started sucessfully
printf("Your registry is being edited please standby....\n\n");
=20
//Opens the proper registry key file
LONG RegOpenKeyEx(
HKEY HKEY_LOCAL_MACHINE,
LPCTSTR Frazell,
DWORD 0,
REGSAM KEY_ALL_ACESS,
PHKEY TEST
);
=20
// Writes to the registry file
LONG RegSetValueEx(
HKEY HKEY_LOCAL_MACHINE,
LPCTSTR Frazell,
DWORD 0,
DWORD REG_BINARY,
CONST BYTE* REGDATA
DWORD 1
);
=20
//Closes program without checking if data change was valid
return 0;
} =20
------------------------------------------------------------ERROR =
CODES--------------------------------------------------------------------=
----------------------
In file included from =
e:\docume~1\admini~1\desktop\cprogr~1\regval~1.c:2:
E:\DEV-C_~1\Include\winreg.h:35: parse error before `REGSAM'
E:\DEV-C_~1\Include\winreg.h:35: warning: data definition has no type or =
storage class
E:\DEV-C_~1\Include\winreg.h:37: parse error before `LPSTR'
E:\DEV-C_~1\Include\winreg.h:37: warning: no semicolon at end of struct =
or union
E:\DEV-C_~1\Include\winreg.h:38: warning: data definition has no type or =
storage class
E:\DEV-C_~1\Include\winreg.h:39: parse error before `ve_valueptr'
E:\DEV-C_~1\Include\winreg.h:39: warning: data definition has no type or =
storage class
E:\DEV-C_~1\Include\winreg.h:40: parse error before `ve_type'
E:\DEV-C_~1\Include\winreg.h:40: warning: data definition has no type or =
storage class
E:\DEV-C_~1\Include\winreg.h:41: warning: data definition has no type or =
storage class
E:\DEV-C_~1\Include\winreg.h:43: parse error before `LPWSTR'
E:\DEV-C_~1\Include\winreg.h:43: warning: no semicolon at end of struct =
or union
E:\DEV-C_~1\Include\winreg.h:44: warning: data definition has no type or =
storage class
E:\DEV-C_~1\Include\winreg.h:45: parse error before `ve_valueptr'
E:\DEV-C_~1\Include\winreg.h:45: warning: data definition has no type or =
storage class
E:\DEV-C_~1\Include\winreg.h:46: parse error before `ve_type'
E:\DEV-C_~1\Include\winreg.h:46: warning: data definition has no type or =
storage class
E:\DEV-C_~1\Include\winreg.h:47: warning: data definition has no type or =
storage class
E:\DEV-C_~1\Include\winreg.h:48: parse error before `WINAPI'
E:\DEV-C_~1\Include\winreg.h:48: warning: parameter names (without =
types) in function declaration
E:\DEV-C_~1\Include\winreg.h:48: warning: data definition has no type or =
storage class
E:\DEV-C_~1\Include\winreg.h:49: parse error before `WINAPI'
E:\DEV-C_~1\Include\winreg.h:49: warning: parameter names (without =
types) in function declaration
E:\DEV-C_~1\Include\winreg.h:49: warning: data definition has no type or =
storage class
E:\DEV-C_~1\Include\winreg.h:50: parse error before `WINAPI'
E:\DEV-C_~1\Include\winreg.h:50: warning: parameter names (without =
types) in function declaration
E:\DEV-C_~1\Include\winreg.h:50: warning: data definition has no type or =
storage class
E:\DEV-C_~1\Include\winreg.h:51: parse error before `WINAPI'
E:\DEV-C_~1\Include\winreg.h:51: warning: parameter names (without =
types) in function declaration
E:\DEV-C_~1\Include\winreg.h:51: warning: data definition has no type or =
storage class
E:\DEV-C_~1\Include\winreg.h:52: parse error before `WINAPI'
E:\DEV-C_~1\Include\winreg.h:52: warning: parameter names (without =
types) in function declaration
E:\DEV-C_~1\Include\winreg.h:52: warning: data definition has no type or =
storage class
E:\DEV-C_~1\Include\winreg.h:53: parse error before `WINAPI'
E:\DEV-C_~1\Include\winreg.h:53: warning: parameter names (without =
types) in function declaration
E:\DEV-C_~1\Include\winreg.h:53: warning: data definition has no type or =
storage class
E:\DEV-C_~1\Include\winreg.h:54: parse error before `WINAPI'
E:\DEV-C_~1\Include\winreg.h:54: warning: parameter names (without =
types) in function declaration
E:\DEV-C_~1\Include\winreg.h:54: warning: data definition has no type or =
storage class
E:\DEV-C_~1\Include\winreg.h:55: parse error before `WINAPI'
E:\DEV-C_~1\Include\winreg.h:55: warning: parameter names (without =
types) in function declaration
E:\DEV-C_~1\Include\winreg.h:55: warning: data definition has no type or =
storage class
E:\DEV-C_~1\Include\winreg.h:56: parse error before `WINAPI'
E:\DEV-C_~1\Include\winreg.h:56: warning: parameter names (without =
types) in function declaration
E:\DEV-C_~1\Include\winreg.h:56: warning: data definition has no type or =
storage class
E:\DEV-C_~1\Include\winreg.h:57: parse error before `WINAPI'
E:\DEV-C_~1\Include\winreg.h:57: warning: parameter names (without =
types) in function declaration
E:\DEV-C_~1\Include\winreg.h:57: warning: data definition has no type or =
storage class
E:\DEV-C_~1\Include\winreg.h:58: parse error before `WINAPI'
E:\DEV-C_~1\Include\winreg.h:58: warning: parameter names (without =
types) in function declaration
E:\DEV-C_~1\Include\winreg.h:58: warning: data definition has no type or =
storage class
E:\DEV-C_~1\Include\winreg.h:59: parse error before `WINAPI'
E:\DEV-C_~1\Include\winreg.h:59: warning: parameter names (without =
types) in function declaration
E:\DEV-C_~1\Include\winreg.h:59: warning: data definition has no type or =
storage class
E:\DEV-C_~1\Include\winreg.h:60: parse error before `WINAPI'
E:\DEV-C_~1\Include\winreg.h:60: warning: parameter names (without =
types) in function declaration
E:\DEV-C_~1\Include\winreg.h:60: warning: data definition has no type or =
storage class
E:\DEV-C_~1\Include\winreg.h:61: parse error before `WINAPI'
E:\DEV-C_~1\Include\winreg.h:61: warning: parameter names (without =
types) in function declaration
E:\DEV-C_~1\Include\winreg.h:61: warning: data definition has no type or =
storage class
E:\DEV-C_~1\Include\winreg.h:62: parse error before `WINAPI'
E:\DEV-C_~1\Include\winreg.h:62: warning: parameter names (without =
types) in function declaration
E:\DEV-C_~1\Include\winreg.h:62: warning: data definition has no type or =
storage class
E:\DEV-C_~1\Include\winreg.h:63: parse error before `WINAPI'
E:\DEV-C_~1\Include\winreg.h:63: warning: parameter names (without =
types) in function declaration
E:\DEV-C_~1\Include\winreg.h:63: warning: data definition has no type or =
storage class
E:\DEV-C_~1\Include\winreg.h:64: parse error before `WINAPI'
E:\DEV-C_~1\Include\winreg.h:64: warning: parameter names (without =
types) in function declaration
E:\DEV-C_~1\Include\winreg.h:64: warning: data definition has no type or =
storage class
E:\DEV-C_~1\Include\winreg.h:65: parse error before `WINAPI'
E:\DEV-C_~1\Include\winreg.h:65: warning: parameter names (without =
types) in function declaration
E:\DEV-C_~1\Include\winreg.h:65: warning: data definition has no type or =
storage class
E:\DEV-C_~1\Include\winreg.h:66: parse error before `WINAPI'
E:\DEV-C_~1\Include\winreg.h:66: warning: parameter names (without =
types) in function declaration
E:\DEV-C_~1\Include\winreg.h:66: warning: data definition has no type or =
storage class
E:\DEV-C_~1\Include\winreg.h:67: parse error before `WINAPI'
E:\DEV-C_~1\Include\winreg.h:67: warning: parameter names (without =
types) in function declaration
E:\DEV-C_~1\Include\winreg.h:67: warning: data definition has no type or =
storage class
E:\DEV-C_~1\Include\winreg.h:68: parse error before `WINAPI'
E:\DEV-C_~1\Include\winreg.h:68: warning: parameter names (without =
types) in function declaration
E:\DEV-C_~1\Include\winreg.h:68: warning: data definition has no type or =
storage class
E:\DEV-C_~1\Include\winreg.h:69: parse error before `WINAPI'
E:\DEV-C_~1\Include\winreg.h:69: warning: parameter names (without =
types) in function declaration
E:\DEV-C_~1\Include\winreg.h:69: warning: data definition has no type or =
storage class
E:\DEV-C_~1\Include\winreg.h:70: parse error before `WINAPI'
E:\DEV-C_~1\Include\winreg.h:70: warning: parameter names (without =
types) in function declaration
E:\DEV-C_~1\Include\winreg.h:70: warning: data definition has no type or =
storage class
E:\DEV-C_~1\Include\winreg.h:71: parse error before `WINAPI'
E:\DEV-C_~1\Include\winreg.h:71: warning: parameter names (without =
types) in function declaration
E:\DEV-C_~1\Include\winreg.h:71: warning: data definition has no type or =
storage class
E:\DEV-C_~1\Include\winreg.h:72: parse error before `WINAPI'
E:\DEV-C_~1\Include\winreg.h:72: warning: parameter names (without =
types) in function declaration
E:\DEV-C_~1\Include\winreg.h:72: warning: data definition has no type or =
storage class
E:\DEV-C_~1\Include\winreg.h:73: parse error before `WINAPI'
E:\DEV-C_~1\Include\winreg.h:73: warning: parameter names (without =
types) in function declaration
E:\DEV-C_~1\Include\winreg.h:73: warning: data definition has no type or =
storage class
E:\DEV-C_~1\Include\winreg.h:74: parse error before `WINAPI'
E:\DEV-C_~1\Include\winreg.h:74: warning: parameter names (without =
types) in function declaration
E:\DEV-C_~1\Include\winreg.h:74: warning: data definition has no type or =
storage class
E:\DEV-C_~1\Include\winreg.h:75: parse error before `WINAPI'
E:\DEV-C_~1\Include\winreg.h:75: warning: parameter names (without =
types) in function declaration
E:\DEV-C_~1\Include\winreg.h:75: warning: data definition has no type or =
storage class
E:\DEV-C_~1\Include\winreg.h:76: parse error before `WINAPI'
E:\DEV-C_~1\Include\winreg.h:76: warning: parameter names (without =
types) in function declaration
E:\DEV-C_~1\Include\winreg.h:76: warning: data definition has no type or =
storage class
E:\DEV-C_~1\Include\winreg.h:77: parse error before `WINAPI'
E:\DEV-C_~1\Include\winreg.h:77: warning: parameter names (without =
types) in function declaration
E:\DEV-C_~1\Include\winreg.h:77: warning: data definition has no type or =
storage class
E:\DEV-C_~1\Include\winreg.h:78: parse error before `WINAPI'
E:\DEV-C_~1\Include\winreg.h:78: warning: parameter names (without =
types) in function declaration
E:\DEV-C_~1\Include\winreg.h:78: warning: data definition has no type or =
storage class
E:\DEV-C_~1\Include\winreg.h:79: parse error before `WINAPI'
E:\DEV-C_~1\Include\winreg.h:79: warning: parameter names (without =
types) in function declaration
E:\DEV-C_~1\Include\winreg.h:79: warning: data definition has no type or =
storage class
E:\DEV-C_~1\Include\winreg.h:80: parse error before `WINAPI'
E:\DEV-C_~1\Include\winreg.h:80: warning: parameter names (without =
types) in function declaration
E:\DEV-C_~1\Include\winreg.h:80: warning: data definition has no type or =
storage class
E:\DEV-C_~1\Include\winreg.h:81: parse error before `WINAPI'
E:\DEV-C_~1\Include\winreg.h:81: warning: parameter names (without =
types) in function declaration
E:\DEV-C_~1\Include\winreg.h:81: warning: data definition has no type or =
storage class
E:\DEV-C_~1\Include\winreg.h:82: parse error before `WINAPI'
E:\DEV-C_~1\Include\winreg.h:82: warning: parameter names (without =
types) in function declaration
E:\DEV-C_~1\Include\winreg.h:82: warning: data definition has no type or =
storage class
E:\DEV-C_~1\Include\winreg.h:83: parse error before `WINAPI'
E:\DEV-C_~1\Include\winreg.h:83: warning: parameter names (without =
types) in function declaration
E:\DEV-C_~1\Include\winreg.h:83: warning: data definition has no type or =
storage class
E:\DEV-C_~1\Include\winreg.h:84: parse error before `WINAPI'
E:\DEV-C_~1\Include\winreg.h:84: warning: parameter names (without =
types) in function declaration
E:\DEV-C_~1\Include\winreg.h:84: warning: data definition has no type or =
storage class
E:\DEV-C_~1\Include\winreg.h:85: parse error before `WINAPI'
E:\DEV-C_~1\Include\winreg.h:85: warning: parameter names (without =
types) in function declaration
E:\DEV-C_~1\Include\winreg.h:85: warning: data definition has no type or =
storage class
E:\DEV-C_~1\Include\winreg.h:86: parse error before `WINAPI'
E:\DEV-C_~1\Include\winreg.h:86: warning: parameter names (without =
types) in function declaration
E:\DEV-C_~1\Include\winreg.h:86: warning: data definition has no type or =
storage class
E:\DEV-C_~1\Include\winreg.h:87: parse error before `WINAPI'
E:\DEV-C_~1\Include\winreg.h:87: warning: parameter names (without =
types) in function declaration
E:\DEV-C_~1\Include\winreg.h:87: warning: data definition has no type or =
storage class
E:\DEV-C_~1\Include\winreg.h:88: parse error before `WINAPI'
E:\DEV-C_~1\Include\winreg.h:88: warning: parameter names (without =
types) in function declaration
E:\DEV-C_~1\Include\winreg.h:88: warning: data definition has no type or =
storage class
E:\DEV-C_~1\Include\winreg.h:89: parse error before `WINAPI'
E:\DEV-C_~1\Include\winreg.h:89: warning: parameter names (without =
types) in function declaration
E:\DEV-C_~1\Include\winreg.h:89: warning: data definition has no type or =
storage class
E:\DEV-C_~1\Include\winreg.h:90: parse error before `WINAPI'
E:\DEV-C_~1\Include\winreg.h:90: warning: parameter names (without =
types) in function declaration
E:\DEV-C_~1\Include\winreg.h:90: warning: data definition has no type or =
storage class
E:\DEV-C_~1\Include\winreg.h:91: parse error before `WINAPI'
E:\DEV-C_~1\Include\winreg.h:91: warning: parameter names (without =
types) in function declaration
E:\DEV-C_~1\Include\winreg.h:91: warning: data definition has no type or =
storage class
E:\DEV-C_~1\Include\winreg.h:92: parse error before `WINAPI'
E:\DEV-C_~1\Include\winreg.h:92: warning: parameter names (without =
types) in function declaration
E:\DEV-C_~1\Include\winreg.h:92: warning: data definition has no type or =
storage class
E:\DEV-C_~1\Include\winreg.h:93: parse error before `WINAPI'
E:\DEV-C_~1\Include\winreg.h:93: warning: parameter names (without =
types) in function declaration
E:\DEV-C_~1\Include\winreg.h:93: warning: data definition has no type or =
storage class
E:\DEV-C_~1\Include\winreg.h:94: parse error before `WINAPI'
E:\DEV-C_~1\Include\winreg.h:94: parse error before `const'
E:\DEV-C_~1\Include\winreg.h:94: warning: data definition has no type or =
storage class
E:\DEV-C_~1\Include\winreg.h:95: parse error before `WINAPI'
E:\DEV-C_~1\Include\winreg.h:95: parse error before `const'
E:\DEV-C_~1\Include\winreg.h:95: warning: data definition has no type or =
storage class
E:\DEV-C_~1\Include\winreg.h:96: parse error before `WINAPI'
E:\DEV-C_~1\Include\winreg.h:96: warning: parameter names (without =
types) in function declaration
E:\DEV-C_~1\Include\winreg.h:96: warning: data definition has no type or =
storage class
E:\DEV-C_~1\Include\winreg.h:97: parse error before `WINAPI'
E:\DEV-C_~1\Include\winreg.h:97: warning: parameter names (without =
types) in function declaration
E:\DEV-C_~1\Include\winreg.h:97: warning: data definition has no type or =
storage class
E:\DEV-C_~1\Include\winreg.h:98: parse error before `WINAPI'
E:\DEV-C_~1\Include\winreg.h:98: warning: parameter names (without =
types) in function declaration
E:\DEV-C_~1\Include\winreg.h:98: warning: data definition has no type or =
storage class
E:\DEV-C_~1\Include\winreg.h:126: parse error before `VALENT'
E:\DEV-C_~1\Include\winreg.h:126: warning: data definition has no type =
or storage class
e:\docume~1\admini~1\desktop\cprogr~1\regval~1.c: In function `main':
e:\docume~1\admini~1\desktop\cprogr~1\regval~1.c:12: parse error before =
`RegOpenKeyExA'
|
|
From: Hoo H. <hoo...@ho...> - 2001-01-03 08:38:01
|
Hi,
This piece of code i wrote sometime ago, hope it helps.
//-----------------------------------------------------------------------=
-------
#include <stdlib.h>
#include <stdio.h>
#include <windows.h>
#include <string>
int main(int argc, char *argv[])
{
HKEY hKey =3D NULL;
=20
DWORD TypeString =3D REG_SZ;
DWORD TypeDword =3D REG_DWORD;
char buf[256];
DWORD RegVal =3D 0;
unsigned long size;
int rv =3D 0;
=20
std::string strKey =3D =
"Software\\Microsoft\\Windows\\CurrentVersion";
std::string strQueryValue1 =3D "RegisteredOwner";
std::string strQueryValue2 =3D "InstallType";
=20
rv =3D RegOpenKeyEx(HKEY_LOCAL_MACHINE,strKey.c_str(),0, =
KEY_ALL_ACCESS, &hKey);
if (rv =3D=3D ERROR_SUCCESS)
printf("RegOpenKeyEx success\n\n");
else
{
printf("RegOpenKeyEx failed, this key does not exist\n");
system("Pause");
return 0;
}
=20
//To query string value
size =3D sizeof(buf); =20
rv =3D RegQueryValueEx(hKey,strQueryValue1.c_str(), NULL, =
&TypeString, (unsigned char *) &buf, &size);
if (rv =3D=3D ERROR_SUCCESS)
printf("The registered owner for this product is %s\n",buf);
else
printf("Error query registry key %s\\%s\n", strKey.c_str(), =
strQueryValue1.c_str());
//To query DWORD value
size =3D sizeof(DWORD); =20
rv =3D RegQueryValueEx(hKey,strQueryValue2.c_str(), NULL, =
&TypeDword, (unsigned char *) &RegVal, &size);
if (rv =3D=3D ERROR_SUCCESS)
printf("The install type is 0x%X\n",RegVal);
else
{
printf("Error query registry key %s\\%s\n", strKey.c_str(), =
strQueryValue2.c_str());
}
=20
HKEY hNewKey =3D NULL;
std::string strNewSubKey =3D "TestKey";
std::string strNewValue =3D "TestValue";
std::string strNewValueData =3D "Testing 123"; =20
DWORD dwDisposition =3D 0;
=20
//To create a new subkey
printf("\nAbout to create new registry key, press Enter to =
continue");
getchar();
rv =3D RegCreateKeyEx(hKey, strNewSubKey.c_str(), 0, NULL, =
REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &hNewKey, =
&dwDisposition);
if (rv =3D=3D ERROR_SUCCESS)
{
if (dwDisposition =3D=3D REG_CREATED_NEW_KEY)
{
printf("New sub key created: %s\\%s\n", strKey.c_str(), =
strNewSubKey.c_str());
printf("Verify it using regedit, press Enter to =
contiue\n");
getchar();
}
else if (dwDisposition =3D=3D REG_OPENED_EXISTING_KEY)
printf("Existing key opened\n");
}
else
printf("Error create new key\n");
if (hNewKey)
{
//To set a new value
printf("About to set new value in new sub key, press Enter to =
continue");
getchar();
rv =3D RegSetValueEx(hNewKey, strNewValue.c_str(), 0, =
TypeString, (unsigned char *) strNewValueData.c_str(), =
strNewValueData.length());
if (rv =3D=3D ERROR_SUCCESS)
{
printf("New value set\n");
printf("Verify it using regedit, press Enter to =
continue\n");
getchar();
}
else
printf("Error setting new key value\n");
=20
//To change the new value
strNewValueData =3D "Testing 456";
printf("About to change new key value data, press Enter to =
continue");
getchar();
rv =3D RegSetValueEx(hNewKey, strNewValue.c_str(), 0, =
TypeString, (unsigned char *) strNewValueData.c_str(), =
strNewValueData.length());
if (rv =3D=3D ERROR_SUCCESS)
{
printf("New value data changed\n");
printf("Verify it using regedit, press Enter to =
continue\n");
getchar();
}
else
printf("Error changing new key value data\n");
=20
//To delete the new value
printf("About to delete new key value, press Enter to =
continue");
getchar();
rv =3D RegDeleteValue(hNewKey, strNewValue.c_str());
if (rv =3D=3D ERROR_SUCCESS)
{
printf("New key value deleted\n");
printf("Verify it using regedit, press Enter to =
continue\n");
getchar();
}
else
printf("Error deleting new key value\n");
}
//To delete new key =20
if (hNewKey)
RegCloseKey(hNewKey);
printf("About to delete new key value, press Enter to continue");
getchar();
rv =3D RegDeleteKey(hKey, strNewSubKey.c_str());
if (rv =3D=3D ERROR_SUCCESS)
{
printf("New key deleted\n");
printf("Verify it using regedit, press Enter to continue\n");
getchar();
}
else
printf("Error deleting new key\n");
=20
=20
if (hKey)
RegCloseKey(hKey);
system("Pause");
return 0;
}
|
|
From: Frazell T. <fr...@fl...> - 2001-01-03 08:43:13
|
is something wrong wit my DevC++ i got 4.1 do i gotta download extra =
libraries cause even urs wouldnt compile :O( any help will be =
appreciated again thankx
----- Original Message -----=20
From: Hoo Hong=20
To: dev...@li...=20
Sent: Wednesday, January 03, 2001 3:12 AM
Subject: Re: [Dev-C++] Reg Prog. (Frazell Thomas)
Hi,
This piece of code i wrote sometime ago, hope it helps.
=
//-----------------------------------------------------------------------=
-------
#include <stdlib.h>
#include <stdio.h>
#include <windows.h>
#include <string>
int main(int argc, char *argv[])
{
HKEY hKey =3D NULL;
=20
DWORD TypeString =3D REG_SZ;
DWORD TypeDword =3D REG_DWORD;
char buf[256];
DWORD RegVal =3D 0;
unsigned long size;
int rv =3D 0;
=20
std::string strKey =3D =
"Software\\Microsoft\\Windows\\CurrentVersion";
std::string strQueryValue1 =3D "RegisteredOwner";
std::string strQueryValue2 =3D "InstallType";
=20
rv =3D RegOpenKeyEx(HKEY_LOCAL_MACHINE,strKey.c_str(),0, =
KEY_ALL_ACCESS, &hKey);
if (rv =3D=3D ERROR_SUCCESS)
printf("RegOpenKeyEx success\n\n");
else
{
printf("RegOpenKeyEx failed, this key does not exist\n");
system("Pause");
return 0;
}
=20
//To query string value
size =3D sizeof(buf); =20
rv =3D RegQueryValueEx(hKey,strQueryValue1.c_str(), NULL, =
&TypeString, (unsigned char *) &buf, &size);
if (rv =3D=3D ERROR_SUCCESS)
printf("The registered owner for this product is %s\n",buf);
else
printf("Error query registry key %s\\%s\n", strKey.c_str(), =
strQueryValue1.c_str());
//To query DWORD value
size =3D sizeof(DWORD); =20
rv =3D RegQueryValueEx(hKey,strQueryValue2.c_str(), NULL, =
&TypeDword, (unsigned char *) &RegVal, &size);
if (rv =3D=3D ERROR_SUCCESS)
printf("The install type is 0x%X\n",RegVal);
else
{
printf("Error query registry key %s\\%s\n", strKey.c_str(), =
strQueryValue2.c_str());
}
=20
HKEY hNewKey =3D NULL;
std::string strNewSubKey =3D "TestKey";
std::string strNewValue =3D "TestValue";
std::string strNewValueData =3D "Testing 123"; =20
DWORD dwDisposition =3D 0;
=20
//To create a new subkey
printf("\nAbout to create new registry key, press Enter to =
continue");
getchar();
rv =3D RegCreateKeyEx(hKey, strNewSubKey.c_str(), 0, NULL, =
REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &hNewKey, =
&dwDisposition);
if (rv =3D=3D ERROR_SUCCESS)
{
if (dwDisposition =3D=3D REG_CREATED_NEW_KEY)
{
printf("New sub key created: %s\\%s\n", strKey.c_str(), =
strNewSubKey.c_str());
printf("Verify it using regedit, press Enter to =
contiue\n");
getchar();
}
else if (dwDisposition =3D=3D REG_OPENED_EXISTING_KEY)
printf("Existing key opened\n");
}
else
printf("Error create new key\n");
if (hNewKey)
{
//To set a new value
printf("About to set new value in new sub key, press Enter to =
continue");
getchar();
rv =3D RegSetValueEx(hNewKey, strNewValue.c_str(), 0, =
TypeString, (unsigned char *) strNewValueData.c_str(), =
strNewValueData.length());
if (rv =3D=3D ERROR_SUCCESS)
{
printf("New value set\n");
printf("Verify it using regedit, press Enter to =
continue\n");
getchar();
}
else
printf("Error setting new key value\n");
=20
//To change the new value
strNewValueData =3D "Testing 456";
printf("About to change new key value data, press Enter to =
continue");
getchar();
rv =3D RegSetValueEx(hNewKey, strNewValue.c_str(), 0, =
TypeString, (unsigned char *) strNewValueData.c_str(), =
strNewValueData.length());
if (rv =3D=3D ERROR_SUCCESS)
{
printf("New value data changed\n");
printf("Verify it using regedit, press Enter to =
continue\n");
getchar();
}
else
printf("Error changing new key value data\n");
=20
//To delete the new value
printf("About to delete new key value, press Enter to =
continue");
getchar();
rv =3D RegDeleteValue(hNewKey, strNewValue.c_str());
if (rv =3D=3D ERROR_SUCCESS)
{
printf("New key value deleted\n");
printf("Verify it using regedit, press Enter to =
continue\n");
getchar();
}
else
printf("Error deleting new key value\n");
}
//To delete new key =20
if (hNewKey)
RegCloseKey(hNewKey);
printf("About to delete new key value, press Enter to continue");
getchar();
rv =3D RegDeleteKey(hKey, strNewSubKey.c_str());
if (rv =3D=3D ERROR_SUCCESS)
{
printf("New key deleted\n");
printf("Verify it using regedit, press Enter to continue\n");
getchar();
}
else
printf("Error deleting new key\n");
=20
=20
if (hKey)
RegCloseKey(hKey);
system("Pause");
return 0;
}
|
|
From: Ramana K. <ra...@my...> - 2001-01-03 08:53:03
|
I havent thoroughly read all this code regarding the registry, but, if Hoo Hongs code works, there may be a difference (or problem) with you system setup, Frazell. What OS are you using, and what does your registry look like (in regedit) compare this with Hoo Hongs. If the program doesnt even compile, yet compiles on another system, maybe you should check all the settings and/or re-install Dev-C++. I saw that your hard drive is E:, Im not sure, but maybe Dev-C++ automatically sets up its default settings to a hard drive which is C:. Go to Options->Compiler Options and check that everything is all right. Does anyone know if there exists a compilation of all the API functions and their argument and what they do? If it exists, Im sure it would be a godsend for the people (like Hoo, Frazell and I) who are working with the Win32 API. I hope we find a solution soon, Xerchzkopfinc. Ramana Kumar ICQ# 93667117 To get paid for surfing the internet, please visit https://www.alladvantage.com/joinsecure.asp?refid=jpn471. -----Original Message----- From: dev...@li... [mailto:dev...@li...]On Behalf Of Frazell Thomas Sent: Wednesday, January 03, 2001 7:43 PM To: dev...@li... Subject: Re: [Dev-C++] Reg Prog. (Frazell Thomas) is something wrong wit my DevC++ i got 4.1 do i gotta download extra libraries cause even urs wouldnt compile :O( any help will be appreciated again thankx ----- Original Message ----- From: Hoo Hong <mailto:hoo...@ho...> To: dev...@li... <mailto:dev...@li...> Sent: Wednesday, January 03, 2001 3:12 AM Subject: Re: [Dev-C++] Reg Prog. (Frazell Thomas) Hi, This piece of code i wrote sometime ago, hope it helps. //-------------------------------------------------------------------------- ---- #include <stdlib.h> #include <stdio.h> #include <windows.h> #include <string> int main(int argc, char *argv[]) { HKEY hKey = NULL; DWORD TypeString = REG_SZ; DWORD TypeDword = REG_DWORD; char buf[256]; DWORD RegVal = 0; unsigned long size; int rv = 0; std::string strKey = "Software\\Microsoft\\Windows\\CurrentVersion"; std::string strQueryValue1 = "RegisteredOwner"; std::string strQueryValue2 = "InstallType"; rv = RegOpenKeyEx(HKEY_LOCAL_MACHINE,strKey.c_str(),0, KEY_ALL_ACCESS, &hKey); if (rv == ERROR_SUCCESS) printf("RegOpenKeyEx success\n\n"); else { printf("RegOpenKeyEx failed, this key does not exist\n"); system("Pause"); return 0; } //To query string value size = sizeof(buf); rv = RegQueryValueEx(hKey,strQueryValue1.c_str(), NULL, &TypeString, (unsigned char *) &buf, &size); if (rv == ERROR_SUCCESS) printf("The registered owner for this product is %s\n",buf); else printf("Error query registry key %s\\%s\n", strKey.c_str(), strQueryValue1.c_str()); //To query DWORD value size = sizeof(DWORD); rv = RegQueryValueEx(hKey,strQueryValue2.c_str(), NULL, &TypeDword, (unsigned char *) &RegVal, &size); if (rv == ERROR_SUCCESS) printf("The install type is 0x%X\n",RegVal); else { printf("Error query registry key %s\\%s\n", strKey.c_str(), strQueryValue2.c_str()); } HKEY hNewKey = NULL; std::string strNewSubKey = "TestKey"; std::string strNewValue = "TestValue"; std::string strNewValueData = "Testing 123"; DWORD dwDisposition = 0; //To create a new subkey printf("\nAbout to create new registry key, press Enter to continue"); getchar(); rv = RegCreateKeyEx(hKey, strNewSubKey.c_str(), 0, NULL, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &hNewKey, &dwDisposition); if (rv == ERROR_SUCCESS) { if (dwDisposition == REG_CREATED_NEW_KEY) { printf("New sub key created: %s\\%s\n", strKey.c_str(), strNewSubKey.c_str()); printf("Verify it using regedit, press Enter to contiue\n"); getchar(); } else if (dwDisposition == REG_OPENED_EXISTING_KEY) printf("Existing key opened\n"); } else printf("Error create new key\n"); if (hNewKey) { //To set a new value printf("About to set new value in new sub key, press Enter to continue"); getchar(); rv = RegSetValueEx(hNewKey, strNewValue.c_str(), 0, TypeString, (unsigned char *) strNewValueData.c_str(), strNewValueData.length()); if (rv == ERROR_SUCCESS) { printf("New value set\n"); printf("Verify it using regedit, press Enter to continue\n"); getchar(); } else printf("Error setting new key value\n"); //To change the new value strNewValueData = "Testing 456"; printf("About to change new key value data, press Enter to continue"); getchar(); rv = RegSetValueEx(hNewKey, strNewValue.c_str(), 0, TypeString, (unsigned char *) strNewValueData.c_str(), strNewValueData.length()); if (rv == ERROR_SUCCESS) { printf("New value data changed\n"); printf("Verify it using regedit, press Enter to continue\n"); getchar(); } else printf("Error changing new key value data\n"); //To delete the new value printf("About to delete new key value, press Enter to continue"); getchar(); rv = RegDeleteValue(hNewKey, strNewValue.c_str()); if (rv == ERROR_SUCCESS) { printf("New key value deleted\n"); printf("Verify it using regedit, press Enter to continue\n"); getchar(); } else printf("Error deleting new key value\n"); } //To delete new key if (hNewKey) RegCloseKey(hNewKey); printf("About to delete new key value, press Enter to continue"); getchar(); rv = RegDeleteKey(hKey, strNewSubKey.c_str()); if (rv == ERROR_SUCCESS) { printf("New key deleted\n"); printf("Verify it using regedit, press Enter to continue\n"); getchar(); } else printf("Error deleting new key\n"); if (hKey) RegCloseKey(hKey); system("Pause"); return 0; } |
|
From: Hoo H. <hoo...@ho...> - 2001-01-03 10:06:15
Attachments:
Reg.cpp
|
hi, I've just tried compiling the piece of code, it works perfectly with Dev C++ as well as MS Visual C++. Don't simply copy the source from your email client and paste it into a .cpp file ... you need to modify a bit because email client may inserts some characters (line feed , carriage return) here and there. Anyway, try to compile the .cpp file attached. If the error persists, I guess there must be a problem with your system or your Dev-C++. |
|
From: Larry H. <lm_...@ya...> - 2001-01-04 19:15:54
|
I was able to compile Hoo Hong's code from the attachment sent, not=20 straight from a copy of the original post. The code does work on my Win98=20 system. I find it very interesting code, and can see some uses in my job,=20 especially for fixing known problems with the registry, or doing custom=20 edits. Granted a .reg file can do the job, but this helps one learn=20 programming skills! <g> I can see how this could be easily modified for=20 custom input during program execution, in a word, cool! I am in the playing stage of working with C/C++, since I do not have time=20 to sit down and really think all this through. I do like the working=20 examples shared on this list though, it sure helps make sense out of the=20 discussions. Larry Hamilton At 07:55 PM 01/03/2001 +1100, you wrote: >I haven=92t thoroughly read all this code regarding the registry, but, if= Hoo >Hong=92s code works, there may be a difference (or problem) with you system >setup, Frazell. What OS are you using, and what does your registry look= like >(in regedit) =AD compare this with Hoo Hong=92s. If the program doesn=92t= even >compile, yet compiles on another system, maybe you should check all the >settings and/or re-install Dev-C++. I saw that your hard drive is E:, I=92m >not sure, but maybe Dev-C++ automatically sets up its default settings to a >hard drive which is C:. Go to Options->Compiler Options and check that >everything is all right. |