RE: [Dev-C++] Reg Prog. (Frazell Thomas)
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
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; } |