Registry Editing C++
-
I seem to have a compatibility issue with functions accessing the registry. All XP systems work well but 98 and 2K seem to decide they won't play. Its common to all Reg...Ex() functions. Anyone know how to solve this cross Windows issue before I start coding everything in 16bit. Many thanks :-D
bool WriteKey(char * key_type, char * key) { bool status = true; // OK LONG ret; HKEY kh1, kh2; DWORD disposition; char *buf1; char *buf2; buf1 = new char[256]; buf2 = new char[256]; // add a key for the new vendor ret = RegCreateKeyEx(HKEY_LOCAL_MACHINE, "SOFTWARE\\KEY1", 0, NULL, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &kh1, &disposition); // add a key for the new app ret = RegCreateKeyEx(kh1, "KEY2", 0, NULL, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &kh2, &disposition); if(ret != ERROR_SUCCESS) { MsgBox("WriteKey(): RegCreateKeyEx: Failed."); status = false; } // create sn ret = RegSetValueEx(kh2, key_type, 0, REG_SZ, (CONST BYTE *) key, strlen(key) + 1); if(ret != ERROR_SUCCESS) { MsgBox("WriteKey(): RegSetValueEx: Failed."); status = false; } // close the new key ret = RegCloseKey(kh1); ret = RegCloseKey(kh2); if(ret != ERROR_SUCCESS) { MsgBox("WriteKey(): RegCloseKey: Failed."); status = false; } delete buf1; delete buf2; return status; }
u6ik -
I seem to have a compatibility issue with functions accessing the registry. All XP systems work well but 98 and 2K seem to decide they won't play. Its common to all Reg...Ex() functions. Anyone know how to solve this cross Windows issue before I start coding everything in 16bit. Many thanks :-D
bool WriteKey(char * key_type, char * key) { bool status = true; // OK LONG ret; HKEY kh1, kh2; DWORD disposition; char *buf1; char *buf2; buf1 = new char[256]; buf2 = new char[256]; // add a key for the new vendor ret = RegCreateKeyEx(HKEY_LOCAL_MACHINE, "SOFTWARE\\KEY1", 0, NULL, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &kh1, &disposition); // add a key for the new app ret = RegCreateKeyEx(kh1, "KEY2", 0, NULL, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &kh2, &disposition); if(ret != ERROR_SUCCESS) { MsgBox("WriteKey(): RegCreateKeyEx: Failed."); status = false; } // create sn ret = RegSetValueEx(kh2, key_type, 0, REG_SZ, (CONST BYTE *) key, strlen(key) + 1); if(ret != ERROR_SUCCESS) { MsgBox("WriteKey(): RegSetValueEx: Failed."); status = false; } // close the new key ret = RegCloseKey(kh1); ret = RegCloseKey(kh2); if(ret != ERROR_SUCCESS) { MsgBox("WriteKey(): RegCloseKey: Failed."); status = false; } delete buf1; delete buf2; return status; }
u6ikCracked it. Simple really...
ret = RegSetValueEx(kh2, key_type, 0, REG_SZ, (CONST BYTE *) key, strlen(key) + 1); if(ret != ERROR_SUCCESS) { ret = RegSetValue(kh2, key_type, (CONST BYTE *) key, strlen(key) + 1); }
Just use the older code if the newer code fails. Bit of a faf, but it works. ;P u6ik