Thread: RegGetValue' : undeclared identifier?

  1. #1
    Registered User
    Join Date
    Aug 2005
    Posts
    20

    RegGetValue' : undeclared identifier?

    can you help me figure out why im getting this error.. here is my code

    Code:
    #include <string>
    #include <stdio.h>
    #include <windows.h>
    #include <tchar.h>
    #include <fstream>
    #include <iostream>
    using namespace std;
    
    ifstream fin;
    ofstream fout;
    
    #define MAX_KEY_LENGTH 255
    #define MAX_VALUE_NAME 16383
     
    void main()
    { 
    
    	fout.open("value.txt");	
    
    	string name = getenv("computername");
    	fout << "workstation name: " << name << endl;
    
    //   DO NOT TOUCH... TOOK FROM MICROSOFTS WEB PAGE!! except where I replaced i with K (for keys
    //   and added V (for values) this way I get enumkeys and enumvalues to loop when I want.
    //////////////////////////////////////////////////////////////////////////////////////	
        TCHAR    achKey[MAX_KEY_LENGTH];   // buffer for subkey name
        DWORD    cbName;                   // size of name string 
        TCHAR    achClass[MAX_PATH] = TEXT("");  // buffer for class name 
        DWORD    cchClassName = MAX_PATH;  // size of class string 
        DWORD    cSubKeys=0;               // number of subkeys 
        DWORD    cbMaxSubKey;              // longest subkey size 
        DWORD    cchMaxClass;              // longest class string 
        DWORD    cValues;              // number of values for key 
        DWORD    cchMaxValue;          // longest value name 
        DWORD    cbMaxValueData;       // longest value data 
        DWORD    cbSecurityDescriptor; // size of security descriptor 
        FILETIME ftLastWriteTime;      // last write time 
     
    
    	TCHAR achData[MAX_VALUE_NAME];
    	DWORD cchData = MAX_VALUE_NAME;
    
    	
    	DWORD  K, V, retCode; 
        TCHAR  achValue[MAX_VALUE_NAME]; 
        DWORD cchValue = MAX_VALUE_NAME; 
    	K=0;
    	
    //////////////////////////////////////////////////////////////////////////////////////
    //  MY STUFF AND MODFIFIED FUNCTIONS FROM MICROSOFT START HERE
    
    
    	int C = 0;
    	int A = 0;	      //tracks the current char value being looked at in Skey
    	int B = 0;        //tracks the current char value for Add
    	int Fix = 0;
    	int Fix2 = 0;	  // sets the limit of loops to the ammount of keys in the innitial Skey value
    					  // was having an issue where it would stop after opening the Sub sub key.. because
    					  // there where no subkeys in that subkey
    	TCHAR add[MAX_KEY_LENGTH] = "";
    	TCHAR Skey[MAX_KEY_LENGTH] = "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\";
    
    
    
    
    do
    {
    
    
    //  Changes Skey back to its original "Software\\....\\Uninstall\\"
    	do
    	{
    		A = 52;
    		if(Skey[A] != NULL && A < 255)
    		{
    			Skey[A] = NULL;
    			A++;
    		}
    		else 
    			A = 255;
    	}
    	while(A < 255);
    	A = 0;
    	B = 0;
    
    // Adds add to the end of Skey	
        A = 52; 
    	
    	if(Fix == 0)
    	{
    		Fix =1;    
    		do
    		{
    			if(add[B] == NULL && Skey[A] == NULL)
    			{
    				A= 255;
    			}
    			if(add[B] == NULL)			
    			{
    				Skey[A] = NULL;
    				A++;
    				B++;
    			}
    	
    			if(Skey[A] == NULL || Skey != NULL)
    			{
    				Skey[A] = add[B];
    				A++;
    				B++;
    			}
    		
    		
    		}
    		while(A < 255);
    		
    	}
    	A = 0;
    	B = 0;
    	
    	
    	
    	HKEY hTestKey = HKEY_LOCAL_MACHINE;
    
    	
    // I CHANGED THE SECOND INPUT FROM BEING A STATIC "\\SOFTWARE\\...ETC to Skey 
    // which can be CHANGED.. YAYAYAYAY.. took long enough.
    	
    	if (RegOpenKeyEx(hTestKey,
    		Skey,
    		0,
    		KEY_READ,
    		&hTestKey) == ERROR_SUCCESS)
    	
    
    	
    // THIS IS MICROSOFTS.. NOT GONNA TOUCH IT UNTILL  IT ADDS A VALUE TO ACHKEY.
    // at this point I need to make ADD = ACHKEY so that ADD will add onto Skey 
    // to search deeper in the regestry
    	
    	 
    // Get the class name and the value count. 
    
    		retCode = RegQueryInfoKey(
    	    hTestKey,                    // key handle 
    	    achClass,                // buffer for class name 
    	    &cchClassName,           // size of class string 
    	    NULL,                    // reserved 
    	    &cSubKeys,               // number of subkeys 
    	    &cbMaxSubKey,            // longest subkey size 
    	    &cchMaxClass,            // longest class string 
    	    &cValues,                // number of values for this key 
    	    &cchMaxValue,            // longest value name 
    	    &cbMaxValueData,         // longest value data 
    	    &cbSecurityDescriptor,   // security descriptor 
    		&ftLastWriteTime);       // last write time 
     
    // Enumerate the subkeys, until RegEnumKeyEx fails.
    		if (Fix2 == 0)
    		{
    			Fix2 = cSubKeys;
    		}
    	    if (cSubKeys)
    	    {
    			if(C == 0)
    			{
    	        fout << "Number of subkeys: " << cSubKeys << endl;
    			C = 1;
    			}
    
                cbName = MAX_KEY_LENGTH;
                retCode = RegEnumKeyEx(hTestKey, K,
                         achKey, 
                         &cbName, 
                         NULL, 
                         NULL, 
                         NULL, 
                         &ftLastWriteTime); 
                if (retCode == ERROR_SUCCESS) 
                {
                    fout << "<" << K+1 << "> " << achKey << endl;
    
                }
    		Fix--;
    		K ++;
    	    } 
    		
    
    
    
    // nulls add and adds achKey to add
    
    	A = 0;
    	B = 0;
    	do
    	{
    		add[A] = NULL;
    		A++;
    	}
    	while(A <255 );
    	A = 0;
    	do
    	{
    		if(achKey[B] == NULL)
    		{
    			A = 255;
    
    		}
    
    		if(achKey[B] != NULL)
    		{
    			add[A] = achKey[B];
    			A++;
    			B++;
    		}
    		
    
    
    	}
    	while(A < 255);
    	A = 0;
    	B = 0;
    
    
    
    
    // Enumerate the key values. 
    
    	    if (cValues) 
    	    {
    			
    	        fout << "     Number of values: " << cValues << endl;
    
    	        for (V=0, retCode=ERROR_SUCCESS; V<cValues; V++) 
    	        { 
    	            cchValue = MAX_VALUE_NAME; 
    	            achValue[0] = '\0'; 
    	            retCode = RegEnumValue(hTestKey, V, 
    	                achValue, 
    	                &cchValue, 
    	                NULL, 
    	                NULL,
    	                NULL,
    		            NULL);
     
    		        if (retCode == ERROR_SUCCESS ) 
    		        { 
    		            fout << "     (" << V+1 << ")" << achValue << endl; 
    				}
    				
    				 RegGetValue(hTestKey,
    							Skey,
    							achValue,
    							NULL,
    							NULL,
    							achData,
    							&cchData);
    
    				cout << achData << endl;
    
    
    
    
    
    
    
    
    		    }
    		
    		}
            
    }
    while(K<Fix2 +1);
    	fout.close();
    }
    sorry about the length.. any help would be greatly appreciated

  2. #2
    Registered User
    Join Date
    Aug 2005
    Posts
    1,267
    There is no such function as RegGetValue(); You probably want RegQueryValue() or RegQueryValueEx()

  3. #3
    Registered User
    Join Date
    Aug 2005
    Posts
    20
    i got the RegGetValue(); from here

    http://msdn.microsoft.com/library/de...eggetvalue.asp

    i dunno.. I tryed RegQueryValueEx(); but i can't get it to work....

    I tryed setting it up like this
    Code:
    RegQueryValueEx(
    	hTestKey,
    	achValue,
    	NULL,
    	NULL,
    	&achData,
    	&cchData);
    the error I get now is this 'RegQueryValueExA' : cannot convert parameter 5 from 'char *' to 'unsigned char *'


    i dunno.. I figued that would be what I would put in it, its supposed to input achValue (which would be something like DisplayName or DisplayVersion) and output achData(which if achValue was DisplayName it would give the value in that which would be the program's name like AOL Instant Messanger) being the value inside

    if you comment out the RegGetValue part an compile it and run it you will see what im trying to do, if I can get that it will create a list of all installed software on the machine

    although there is another error, but i'll fix that.. if it runs accross a key that has another key under it the program will stop at that.. but thats ok, I'll fix that.. I just want to get the data in the value's for now.


    the example on the site gives this
    http://msdn.microsoft.com/library/de...eryvalueex.asp

    LONG RegQueryValueEx(
    HKEY hKey,
    LPCTSTR lpValueName,
    LPDWORD lpReserved,
    LPDWORD lpType,
    LPBYTE lpData,
    LPDWORD lpcbData
    );
    what is a LPBYTE ?
    Last edited by Sephiroth222; 09-24-2005 at 07:24 AM.

  4. #4
    ^ Read Backwards^
    Join Date
    Sep 2005
    Location
    Earth
    Posts
    282
    From the site you linked, it looks like it returns a value. You are calling the function but doing nothing with the value(s) it returns.

  5. #5
    Registered User
    Join Date
    Aug 2005
    Posts
    20
    well.. from what I can tell so far.. I don't even need to use the RegQueryValueEx() function.. because RegEnumValue(); seems like it should do what I need it to do if I use the rest of it (instead of setting the values in it to null.

    Example
    Code:
    RegQueryValueEx(
    	hTestKey,
    	achValue,
    	NULL,
    	NULL,
                    NULL, <=== This is supposed to return what I need.. but I can't figure out how
    	&cchData);
    and this from my code above with a change (noted in red)
    Code:
    RegEnumValue(hTestKey, V, 
    	                achValue, 
    	                &cchValue, 
    	                NULL, 
    	                NULL,
    	                NULL, <== This is supposed to return what I need.. but I can't figure out how
    
    		&cchData);
    in both cases cchData returnes the same value and prints the same value when Icout it.. it is the number of characters in the value that RegEnumValue grabs for me.. what I mean is this.. achvalue which is returned by the function gives me the value title eg DisplayName
    what the variable imsupposed to put into the NULL spot noted above is supposed to be the Data contained in the value Display name.

    here is a piece of the output of the program i wrote so far

    <6> Azureus
    Number of values: 7
    (1)UninstallString
    39
    (2)InstallLocation
    25
    (3)DisplayName
    8
    (4)DisplayIcon
    39
    (5)DisplayVersion
    8
    (6)NoModify
    4
    (7)NoRepair
    4

    ok.. let me break this down..
    this is from MY regestry
    <6>Azureus

    this is the 6th entry in my regestry under the key I opened
    Number of values: 7

    this is the number of values under the key Azureus
    (1)UninstallString

    this i the first value under azurus it is titled uninstall string this containes DATA which i need to get to ..
    39
    that is the number of characters the data is in the uninstall string valuename.

    the spot i pointed at is supposed to output that data.. how do I do that using the function

  6. #6
    Registered User
    Join Date
    Aug 2005
    Posts
    20
    odd....

    after playing around with it a bit... i took the variable i created

    TCHAR achData[MAX_VALUE_NAME];

    and changed it from TCHAR to BYTE (was just guessing.. didn't know there was a BYTE data type....)
    and I decided to output the value achData and im KINDA getting what I wanted.. it went from what I posted above to this.. kinda what i wanted.. but kinda messed up


    <4> Aston12
    Number of values: 6
    (1)DisplayName
    Aston 1.9.1

    (3)DisplayVersion
    Aston 1.9.0

    (5)Publisher
    Gladiators Software

    <5> ATI Display Driver
    Number of values: 3
    (1)DisplayName
    ATI Display Driver

    (3)DisplayVersion
    8.162-050803a2-025203C-ATI
    <6> Azureus
    Number of values: 7

    (2)InstallLocation
    C:\Program Files\Azureus
    (3)DisplayName
    Azureus

    (5)DisplayVersion
    2.3.0.4
    (6)NoModify
    
    (7)NoRepair
    

  7. #7
    Registered User
    Join Date
    Aug 2005
    Posts
    20
    yay got it workin.. post the code in a bit

  8. #8
    Registered User
    Join Date
    Aug 2005
    Posts
    20
    as messy as it is.. here ya go!

    oh yeah.. theres still that issue where it won't go the whole way sometimes if it hits a key that has keys under it.. im gonna fix that later..

    Code:
    #include <string>
    #include <stdio.h>
    #include <windows.h>
    #include <tchar.h>
    #include <fstream>
    #include <iostream>
    using namespace std;
    
    ifstream fin;
    ofstream fout;
    
    #define MAX_KEY_LENGTH 255
    #define MAX_VALUE_NAME 16383
     
    void main()
    { 
    
    	fout.open("value.txt");	
    
    	string name = getenv("computername");
    	fout << "workstation name: " << name << endl;
    
    //   DO NOT TOUCH... TOOK FROM MICROSOFTS WEB PAGE!! except where I replaced i with K (for keys
    //   and added V (for values) this way I get enumkeys and enumvalues to loop when I want.
    //////////////////////////////////////////////////////////////////////////////////////	
        TCHAR    achKey[MAX_KEY_LENGTH];   // buffer for subkey name
        DWORD    cbName;                   // size of name string 
        TCHAR    achClass[MAX_PATH] = TEXT("");  // buffer for class name 
        DWORD    cchClassName = MAX_PATH;  // size of class string 
        DWORD    cSubKeys=0;               // number of subkeys 
        DWORD    cbMaxSubKey;              // longest subkey size 
        DWORD    cchMaxClass;              // longest class string 
        DWORD    cValues;              // number of values for key 
        DWORD    cchMaxValue;          // longest value name 
        DWORD    cbMaxValueData;       // longest value data 
        DWORD    cbSecurityDescriptor; // size of security descriptor 
        FILETIME ftLastWriteTime;      // last write time 
     
    	DWORD cchData = MAX_VALUE_NAME;
    	BYTE achData[MAX_VALUE_NAME];
    
    
    	
    	DWORD  K, V, retCode; 
        TCHAR  achValue[MAX_VALUE_NAME]; 
        DWORD cchValue = MAX_VALUE_NAME; 
    	K=0;
    	
    //////////////////////////////////////////////////////////////////////////////////////
    //  MY STUFF AND MODFIFIED FUNCTIONS FROM MICROSOFT START HERE
    
    
    	int C = 0;
    	int A = 0;	      //tracks the current char value being looked at in Skey
    	int B = 0;        //tracks the current char value for Add
    	int Fix = 0;
    	int Fix2 = 0;	  // sets the limit of loops to the ammount of keys in the innitial Skey value
    					  // was having an issue where it would stop after opening the Sub sub key.. because
    					  // there where no subkeys in that subkey
    	TCHAR add[MAX_KEY_LENGTH] = "";
    	TCHAR Skey[MAX_KEY_LENGTH] = "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\";
    
    
    
    
    do
    {
    
    
    //  Changes Skey back to its original "Software\\....\\Uninstall\\"
    	do
    	{
    		A = 52;
    		if(Skey[A] != NULL && A < 255)
    		{
    			Skey[A] = NULL;
    			A++;
    		}
    		else 
    			A = 255;
    	}
    	while(A < 255);
    	A = 0;
    	B = 0;
    
    // Adds add to the end of Skey	
        A = 52; 
    	
    	if(Fix == 0)
    	{
    		Fix =1;    
    		do
    		{
    			if(add[B] == NULL && Skey[A] == NULL)
    			{
    				A= 255;
    			}
    			if(add[B] == NULL)			
    			{
    				Skey[A] = NULL;
    				A++;
    				B++;
    			}
    	
    			if(Skey[A] == NULL || Skey != NULL)
    			{
    				Skey[A] = add[B];
    				A++;
    				B++;
    			}
    		
    		
    		}
    		while(A < 255);
    		
    	}
    	A = 0;
    	B = 0;
    	
    	
    	
    	HKEY hTestKey = HKEY_LOCAL_MACHINE;
    
    	
    // I CHANGED THE SECOND INPUT FROM BEING A STATIC "\\SOFTWARE\\...ETC to Skey 
    // which can be CHANGED.. YAYAYAYAY.. took long enough.
    	
    	if (RegOpenKeyEx(hTestKey,
    		Skey,
    		0,
    		KEY_READ,
    		&hTestKey) == ERROR_SUCCESS)
    	
    
    	
    // THIS IS MICROSOFTS.. NOT GONNA TOUCH IT UNTILL  IT ADDS A VALUE TO ACHKEY.
    // at this point I need to make ADD = ACHKEY so that ADD will add onto Skey 
    // to search deeper in the regestry
    	
    	 
    // Get the class name and the value count. 
    
    		retCode = RegQueryInfoKey(
    	    hTestKey,                    // key handle 
    	    achClass,                // buffer for class name 
    	    &cchClassName,           // size of class string 
    	    NULL,                    // reserved 
    	    &cSubKeys,               // number of subkeys 
    	    &cbMaxSubKey,            // longest subkey size 
    	    &cchMaxClass,            // longest class string 
    	    &cValues,                // number of values for this key 
    	    &cchMaxValue,            // longest value name 
    	    &cbMaxValueData,         // longest value data 
    	    &cbSecurityDescriptor,   // security descriptor 
    		&ftLastWriteTime);       // last write time 
     
    // Enumerate the subkeys, until RegEnumKeyEx fails.
    		if (Fix2 == 0)
    		{
    			Fix2 = cSubKeys;
    		}
    	    if (cSubKeys)
    	    {
    			if(C == 0)
    			{
    	        fout << "Number of subkeys: " << cSubKeys << endl;
    			C = 1;
    			}
    
                cbName = MAX_KEY_LENGTH;
                retCode = RegEnumKeyEx(hTestKey, K,
                         achKey, 
                         &cbName, 
                         NULL, 
                         NULL, 
                         NULL, 
                         &ftLastWriteTime); 
                if (retCode == ERROR_SUCCESS) 
                {
                    fout << "<" << K+1 << "> " << achKey << endl;
    
                }
    		Fix--;
    		K ++;
    	    } 
    		
    
    
    
    // nulls add and adds achKey to add
    
    	A = 0;
    	B = 0;
    	do
    	{
    		add[A] = NULL;
    		A++;
    	}
    	while(A <255 );
    	A = 0;
    	do
    	{
    		if(achKey[B] == NULL)
    		{
    			A = 255;
    
    		}
    
    		if(achKey[B] != NULL)
    		{
    			add[A] = achKey[B];
    			A++;
    			B++;
    		}
    		
    
    
    	}
    	while(A < 255);
    	A = 0;
    	B = 0;
    
    
    
    
    // Enumerate the key values. 
    
    	    if (cValues) 
    	    {
    			
    	        fout << "     Number of values: " << cValues << endl;
    
    	        for (V=0, retCode=ERROR_SUCCESS; V<cValues; V++) 
    	        { 
    				cchData = MAX_VALUE_NAME;
    	            cchValue = MAX_VALUE_NAME; 
    	            achValue[0] = '\0'; 
    				achData[0] = '\0'; 
    	            retCode = RegEnumValue(hTestKey, V, 
    	                achValue, 
    	                &cchValue, 
    	                NULL, 
    	                NULL,
    	                achData,
    		            &cchData);
     
    		            fout << "     (" << V+1 << ")" << achValue << endl; 
    					fout << "        " << achData << endl;
    		    }
    		
    		}
            
    }
    while(K<Fix2 +1);
    	fout.close();
    }
    Last edited by Sephiroth222; 09-24-2005 at 11:41 AM.

  9. #9
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    Code:
    TCHAR Skey[MAX_KEY_LENGTH] = "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Unin  stall\\";
    Are those spaces supposed to be there?
    Code:
    while(K<Fix2 +1);
    	fout.close();
    I think that's an infinite loop . . . and it doesn't do what you think it does, with that semicolon.

    main is supposed to return int.

    You don't need any global variables, since you only have one function.

    Code:
    		if(achKey[B] == NULL)
    		{
    			A = 255;
    
    		}
    
    		if(achKey[B] != NULL)  // this line could be 'else'
    This if
    Code:
    if(Fix == 0)
    	{
    		Fix =1;    
    		do
    		{
    is useless, since Fix is always 0 at that point.
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  10. #10
    Registered User
    Join Date
    Aug 2005
    Posts
    20
    Code:
    if(Fix == 0)
    	{
    		Fix =1;    
    		do
    		{
    actually no its not.. when it loops back the second time fix will be = to 1 so it won't go into that if loop and it will later be set back to 0 so the third time it loops it will go int the if loop.

    Code:
    while(K<Fix2 +1);
    I thought at the end of a do while loop you are supposed to have a semicolon.. otherwise it won't compile.......

    main dosn't HAVE to return an int.. I don't see why my prog should need to

    Code:
    TCHAR Skey[MAX_KEY_LENGTH] = "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Unin    stall\\";
    no the spaces arn't supposed to be there.. copying my code and pasting it in the window messed it up for some reason.

    the global variables are there because I built my program around code found here..

    http://msdn.microsoft.com/library/de...ry_subkeys.asp

    I moved everything into 1 function because I couldnt' figure out how to pass arrays between functions, and this is the first thing ive done in 4 years.

    also im gonna change it when my prog is done.. I just want everything to be working.. then I'll re-wright it so its alittle shorter and works more efficiantly.. now that im remembering how to do things.
    Last edited by Sephiroth222; 09-25-2005 at 05:10 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. An error is driving me nuts!
    By ulillillia in forum C Programming
    Replies: 5
    Last Post: 04-04-2009, 09:15 PM
  2. Game Pointer Trouble?
    By Drahcir in forum C Programming
    Replies: 8
    Last Post: 02-04-2006, 02:53 AM
  3. Why wont my function exit correctly?
    By LightsOut06 in forum C Programming
    Replies: 2
    Last Post: 10-09-2005, 09:23 PM
  4. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM
  5. Problem with Visual C++ Object-Oriented Programming Book.
    By GameGenie in forum C++ Programming
    Replies: 9
    Last Post: 08-29-2005, 11:21 PM