Another newbie having problem with the registry 
Author Message
 Another newbie having problem with the registry

Hello everyone,
               I'm currently trying to successfully read registry. I'm
trying to read multiple string from a registry key. I'm connecting to
the key using RegOpenKeyEx(). After i'm trying to read all the key
string invidualy with the RegQueryValueEx() function.

This is where i'm encontering problems. I'm just able to read the first
one, the program failing to read the next key string. I also try
reading from my second key string. This way I was able to read four key
string, the program failed to read my last key string.

My first impression was to say that maybe this function is not suitable
to read multiple key string. Maybe I should try using the
RegQueryMultipleValues(), wich I failed to make it use.

So, I'm confuse, angry and desperate so if anybody would mind to give
my a clue, it will be very appreciate.

There is a sample of my code, if you mind to look.

 HKEY   hKey;
 DWORD  dwType, dwSize = 256;
 LONG   IVal;
 const  char *szKeyName = "SOFTWARE\\recon";
 BYTE   szKeyValue[6][256];

 /* Open key */
 IVal = RegOpenKeyEx(HKEY_LOCAL_MACHINE,szKeyName,0,KEY_READ,&hKey);
 if(IVal != ERROR_SUCCESS)
 {
         cout<< "\nEtes-vous le maitre des clefs ?";
         exit(1);
 }

 /* Read first string */
 IVal = RegQueryValueEx(hKey,"DB_Host",NULL,&dwType,szKeyValue
[0],&dwSize);
 if(IVal != ERROR_SUCCESS)
 {
         cout<< "\nAgain";
         RegCloseKey(hKey);
         exit(1);
 }

 cout<<"\nHost : "<<szKeyValue[0];

 /* Read second string */
 IVal = RegQueryValueEx(hKey,"DB_Password",NULL,&dwType,szKeyValue
[1],&dwSize);
 if(IVal != ERROR_SUCCESS)
 {
  cout<< "\nAgain 2";
  RegCloseKey(hKey);
  exit(1);
 }

 cout<<"\nPassword : "<<szKeyValue[1];

 ... /* read the other key string */

 RegCloseKey(hKey);

Thanks in advance.

Francis Vaudry

Sent via Deja.com http://www.*-*-*.com/
Before you buy.



Sat, 27 Jul 2002 03:00:00 GMT  
 Another newbie having problem with the registry
I would do it a little different. I would try and do it with a CString and a
buffer. This definately works:

CString m_text;
LONG  lResult;
CRegKey Key;
 lResult=Key.Open(HKEY_LOCAL_MACHINE,_T("SOFTWARE\\recon"),KEY_ALL_ACCESS);
 if(ERROR_SUCCESS==lResult){
  CString strValue;
  // Declare a variable to hold the size of buffer
   DWORD dwSize=1000;
   // Get the value
  lResult=Key.QueryValue(strValue.GetBuffer(dwSize),
       _T("DB_Host"), &dwSize);
  // Make sure to release the CString buffer
 strValue.ReleaseBuffer();
 // Display the result
 if(ERROR_SUCCESS==lResult){
          m_text=" \nHost : "+str;
          cou<<m_text;

Quote:
}
}

Keep Querying the different keys and output the result. It will work this
way.


Quote:
> Hello everyone,
>                I'm currently trying to successfully read registry. I'm
> trying to read multiple string from a registry key. I'm connecting to
> the key using RegOpenKeyEx(). After i'm trying to read all the key
> string invidualy with the RegQueryValueEx() function.

> This is where i'm encontering problems. I'm just able to read the first
> one, the program failing to read the next key string. I also try
> reading from my second key string. This way I was able to read four key
> string, the program failed to read my last key string.

> My first impression was to say that maybe this function is not suitable
> to read multiple key string. Maybe I should try using the
> RegQueryMultipleValues(), wich I failed to make it use.

> So, I'm confuse, angry and desperate so if anybody would mind to give
> my a clue, it will be very appreciate.

> There is a sample of my code, if you mind to look.

>  HKEY hKey;
>  DWORD dwType, dwSize = 256;
>  LONG IVal;
>  const char *szKeyName = "SOFTWARE\\recon";
>  BYTE szKeyValue[6][256];

>  /* Open key */
>  IVal = RegOpenKeyEx(HKEY_LOCAL_MACHINE,szKeyName,0,KEY_READ,&hKey);
>  if(IVal != ERROR_SUCCESS)
>  {
> cout<< "\nEtes-vous le maitre des clefs ?";
> exit(1);
>  }

>  /* Read first string */
>  IVal = RegQueryValueEx(hKey,"DB_Host",NULL,&dwType,szKeyValue
> [0],&dwSize);
>  if(IVal != ERROR_SUCCESS)
>  {
> cout<< "\nAgain";
> RegCloseKey(hKey);
> exit(1);
>  }

>  cout<<"\nHost : "<<szKeyValue[0];

>  /* Read second string */
>  IVal = RegQueryValueEx(hKey,"DB_Password",NULL,&dwType,szKeyValue
> [1],&dwSize);
>  if(IVal != ERROR_SUCCESS)
>  {
>   cout<< "\nAgain 2";
>   RegCloseKey(hKey);
>   exit(1);
>  }

>  cout<<"\nPassword : "<<szKeyValue[1];

>  ... /* read the other key string */

>  RegCloseKey(hKey);

> Thanks in advance.

> Francis Vaudry

> Sent via Deja.com http://www.deja.com/
> Before you buy.



Sat, 27 Jul 2002 03:00:00 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Newbie having problems with General Protection Exception

2. Having a newbie problem....

3. Newbie having problems making/finding the exe

4. Newbie problem writing to registry

5. newbie having trouble

6. newbie having compiling issues

7. Newbie having probs

8. Newbie having another prob

9. Newbie having trouble finding grid samples

10. Newbie - registry and return values from a subroutine

11. binary entry into registry by a newbie

12. binary entry into registry by a newbie

 

 
Powered by phpBB® Forum Software