   Win32 registry fun (on WinXP)
  I have recently had a go at setting up my tilemap editor so a) it would open files in a new instance of the program if I double-clicked it, and b) it would add the file to the list of recently viewed documents in Start->Documents if I opened it.I did it, but had a devil of a time and only half understand what I did to make it work. Not helped by the fact that after pecking at it half-heartedly for an hour or so without success this morning, it suddenly started working for no reason I knew of. I hate when that happens So I was wondering if you would just look this over. Some of it just because I was told to, which is probably the parts going over my head (why am I even making a ShellNew key with no info? ) I guess, just let me know if I'm doing something unnecessary or unwise, or if there's any way to clean it up or improve it in some other way or something ... yeah void DoRegistryStuff() {// registry fun time!!!!HKEYhkey;DWORDdwDisposition;string s1 = "MapSlapper";string s2 = "C:\\Program Files\\MapSlapper\\MapSlapper.exe %1";string s3 = "C:\\Program Files\\MapSlapper\\icon.ico";string s4 = "MapSlapper map file";if(RegCreateKeyEx(HKEY_CLASSES_ROOT, TEXT(".map"), 0, NULL, REG_OPTION_NON_VOLATILE, 0, NULL, &hkey, &dwDisposition) == ERROR_SUCCESS){RegSetValueEx(hkey, TEXT(""), 0, REG_SZ, (PBYTE)s1.c_str(), s1.size() + 1);RegCloseKey(hkey);}elseMessageBox(NULL, "One crap ...", "", MB_OK);if(RegCreateKeyEx(HKEY_CLASSES_ROOT, TEXT(".map\\ShellNew"), 0, NULL, REG_OPTION_NON_VOLATILE, 0, NULL, &hkey, &dwDisposition) == ERROR_SUCCESS){RegSetValueEx(hkey, TEXT("NullFile"), 0, REG_SZ, (PBYTE)"", 0);RegCloseKey(hkey);}elseMessageBox(NULL, "Two crap ...", "", MB_OK);if(RegCreateKeyEx(HKEY_CLASSES_ROOT, TEXT("MapSlapper"), 0, NULL, REG_OPTION_NON_VOLATILE, 0, NULL, &hkey, &dwDisposition) == ERROR_SUCCESS){RegSetValueEx(hkey, TEXT(""), 0, REG_SZ, (PBYTE)s4.c_str(), s4.size() + 1);RegCloseKey(hkey);}elseMessageBox(NULL, "Three crap ...", "", MB_OK);if(RegCreateKeyEx(HKEY_CLASSES_ROOT, TEXT("MapSlapper\\Shell\\Open\\command"), 0, NULL, REG_OPTION_NON_VOLATILE, 0, NULL, &hkey, &dwDisposition) == ERROR_SUCCESS){RegSetValueEx(hkey, TEXT(""), 0, REG_SZ, (PBYTE)s2.c_str(), s2.size() + 1);RegCloseKey(hkey);}elseMessageBox(NULL, "Four crap ...", "", MB_OK);if(RegCreateKeyEx(HKEY_CLASSES_ROOT, TEXT("MapSlapper\\DefaultIcon"), 0, NULL, REG_OPTION_NON_VOLATILE, 0, NULL, &hkey, &dwDisposition) == ERROR_SUCCESS){RegSetValueEx(hkey, TEXT(""), 0, REG_SZ, (PBYTE)s3.c_str(), s3.size() + 1);RegCloseKey(hkey);}elseMessageBox(NULL, "Five crap ...", "", MB_OK);// apply changes right now. Now! NOW!!SHChangeNotify(SHCNE_ASSOCCHANGED, SHCNF_IDLIST, NULL, NULL);}Adding the file to Recent Documents is easy enough:string recent = '\"' + filename + '\"';SHAddToRecentDocs(SHARD_PATH, recent.c_str());    Comments? Is it all good, does it suck ...   Jesus saves ... the rest of you take damage."A page of history is worth a volume of logic." -- Oliver Wendell Holmes  [edited by - 23yrold3yrold on January 18, 2004 3:13:33 PM][edited by - 23yrold3yrold on February 4, 2004 9:08:54 PM]
  Looks fine to me.   [Mercury Software] [Google!] [ Look I DONT Follow Trends ]  ;  Sorry for the partial necro ...The above code works in Win98, but fails miserably in WindowsXP. See all those "* crap" message boxes? I see all five when I run the program on an XP box. I''m fairly inexperienced with WinXP; is there something special I need to do to get through the OS''s security or something?   Jesus saves ... the rest of you take damage."A page of history is worth a volume of logic." -- Oliver Wendell Holmes;  Are you running the code as an administrator? Normal users can''t change much (if anything) in the registry under XP. ;  Yeah, you may not have access to HKEY_CLASSES_ROOT...try HKEY_CURRENT_USER, maybe? ;  You know, RegCreateKeyEx() returns error codes for a reason. Maybe you should try displaying the exact return value is. It might be more helpful than us forum monkeys throwing out random guesses. ;  I second the motion to use HKEY_CURRENT_USER.  This way, a new user doesn''t see another users recent file list, but instead would have their own.- Houdini ;  Okay, I''m back. Been a long week I''m checking the error returned from RegCreateKeyEx() and it''s always "Access is denied". I''m the administrator (it''s my home computer). HKEY_CLASSES_ROOT and HKEY_CURRENT_USER both give me the error.   Jesus saves ... the rest of you take damage."A page of history is worth a volume of logic." -- Oliver Wendell Holmes