Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Registry Editing C++

Registry Editing C++

Scheduled Pinned Locked Moved C / C++ / MFC
c++windows-adminhelptutorial
2 Posts 1 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • U Offline
    U Offline
    u6ik
    wrote on last edited by
    #1

    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

    U 1 Reply Last reply
    0
    • U 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; } u6ik

      U Offline
      U Offline
      u6ik
      wrote on last edited by
      #2

      Cracked 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

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups