Thread: why doesn't the registry work?

  1. #1
    Software Developer jverkoey's Avatar
    Join Date
    Feb 2003
    Location
    New York
    Posts
    1,905

    why doesn't the registry work?

    why is it, that I can save some registry info and it works in XP, but when i run the same program on 98, it doesn't do anything?

    here is my code:

    Code:
    //include stuff
    
    void writetoKey(HKEY keypath, char *keyname, unsigned int type, char *value)
    {
    	unsigned long result;
    	HKEY key;
    
    	RegCreateKeyEx(
    		keypath,
    		keyname,
    		0,
    		NULL,
    		REG_OPTION_NON_VOLATILE,
    		KEY_SET_VALUE,
    		NULL,
    		&key,
    		&result
    		);
    
    	switch(result)
    	{
    	case REG_CREATED_NEW_KEY:
    		cout << "Created new key" << endl;
    		break;
    	case REG_OPENED_EXISTING_KEY:
    		cout << "Key already existed, rewriting" << endl;
    	}
    
    	RegSetValueEx(
    		key,
    		NULL,
    		0,
    		type,
    		(LPBYTE)value,
    		strlen(value)+1
    		);
    
    	RegFlushKey(key);
    	
    	RegCloseKey(key);
    }
    
    int main()
    {
    	char fullpath[]="C:\testfolder\EXE\OpenScript.exe %1";
    	char tempname[]="ost_auto_file";
    
    	char tempname2[]="%SystemRoot%\\system32\\NOTEPAD.EXE %1";
    
    	writetoKey(HKEY_CLASSES_ROOT,".ost",REG_SZ,tempname);
    	writetoKey(HKEY_CLASSES_ROOT,"ost_auto_file\\shell\\edit\\command\\",REG_EXPAND_SZ,tempname2);
    	writetoKey(HKEY_CLASSES_ROOT,"ost_auto_file\\shell\\open\\command\\",REG_EXPAND_SZ,fullpath);
    	return 1;
    }
    any help would be greatly appreciated. I need to know if there is a way to edit the registry on ALL (or most) operating systems...

    -thanks in advance

  2. #2
    Skunkmeister Stoned_Coder's Avatar
    Join Date
    Aug 2001
    Posts
    2,572
    which api function fails? what does GetLastError() return. Use FormatMessage() to get a string error msg. I know people who program for windows who wrap up every api call in a macro that calls GetLastError and FormatMessage. That could bbe useful for debugging things like this but I wouldnt advise using macros in c++.
    Free the weed!! Class B to class C is not good enough!!
    And the FAQ is here :- http://faq.cprogramming.com/cgi-bin/smartfaq.cgi

  3. #3
    Software Developer jverkoey's Avatar
    Join Date
    Feb 2003
    Location
    New York
    Posts
    1,905
    ok, lmao, it turns out, it was elsewhere in my code

    in my installer, i have to call my wrap program (wrap.exe) and it returns a value as to whether or not an error occured, so i did something like so:
    if(!system("wrap.exe Installdata.wrap C:\testfolder"))
    return 0;

    in other words, it's kinda like a function, but actually running another exe....

    now, i noticed that i tried to output stuff after i had unwrapped everything, and it wouldn't output anything in 98....so what i'm guessing is that windows doesn't support jumping back IN to the calling program, and that it just stops after the called one is done.....

    i don't know, i'm just assuming that, maybe someone else can give some light to this situation?

  4. #4
    Registered User johnnie2's Avatar
    Join Date
    Aug 2001
    Posts
    186
    Originally posted by jverkoey
    now, i noticed that i tried to output stuff after i had unwrapped everything, and it wouldn't output anything in 98....so what i'm guessing is that windows doesn't support jumping back IN to the calling program, and that it just stops after the called one is done.....
    Or the wrap program stalls and never returns control to the caller.
    "Optimal decisions, once made, do not need to be changed." - Robert Sedgewick, Algorithms in C

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Why don't the tutorials on this site work on my computer?
    By jsrig88 in forum C++ Programming
    Replies: 3
    Last Post: 05-15-2006, 10:39 PM
  2. Problems in getting OpenGL to work
    By zonf in forum C Programming
    Replies: 5
    Last Post: 02-13-2006, 04:48 AM
  3. Why won't my OpenGL work?
    By Raigne in forum C++ Programming
    Replies: 7
    Last Post: 11-26-2005, 11:53 AM
  4. fopen();
    By GanglyLamb in forum C Programming
    Replies: 8
    Last Post: 11-03-2002, 12:39 PM
  5. DLL __cdecl doesnt seem to work?
    By Xei in forum C++ Programming
    Replies: 6
    Last Post: 08-21-2002, 04:36 PM