CRegKey::QueryValue not working 
Author Message
 CRegKey::QueryValue not working

Hi,

I'm trying to write a custom DLL for uninstallation that renames a
file.  I'm using CRegKey to get the path of the file I need to rename,
the problem arises when I use CRegKey::QueryValue.  Instead of returning
the proper queried string, it returns nothing, and gives an error code
87, which I believe is ERROR_INVALID_PARAMETER.  However, I've quintuple
checked my parameters and they are all of the correct type. Any help
would be appreciated, my code is listed below:

#include <afx.h>    //For CString
#include <atlbase.h>    //For CRegKey
#include <atlimpl.cpp>    //For CRegKey

 unsigned long lSize;
 long errcode;
 CRegKey theKey;
 CString key = _T("SOFTWARE\\..<blahblah>.\\Image-Pro Plus 4.0");
 CString myPath;
 CString older;
 CString newer;

if (ERROR_SUCCESS == theKey.Open(HKEY_LOCAL_MACHINE, key,
KEY_ALL_ACCESS))
{
//Note: Opens Key fine.....

errcode = theKey.QueryValue(myPath.GetBuffer(_MAX_PATH),
_T("LocalRootPath"), &lSize);

//errorcode==ERR_INVAL_PARAM    HELP!!!

if (errcode == ERROR_SUCCESS)
//Never get here...
 {
  myPath.ReleaseBuffer(lSize);
  older = myPath + "\\mccapt32.bak";
  newer = myPath + "\\mccapt32.dll";
  rename( older, newer );
  theKey.Close();
 }

Any Ideas????

Thanks :)



Sun, 03 Mar 2002 03:00:00 GMT  
 CRegKey::QueryValue not working

Quote:

> Hi,

> I'm trying to write a custom DLL for uninstallation that renames a
> file.  I'm using CRegKey to get the path of the file I need to rename,
> the problem arises when I use CRegKey::QueryValue.  Instead of
> returning the proper queried string, it returns nothing, and gives an
> error code 87, which I believe is ERROR_INVALID_PARAMETER.  However,
> I've quintuple checked my parameters and they are all of the correct
> type. Any help would be appreciated, my code is listed below:

> #include <afx.h>    //For CString
> #include <atlbase.h>    //For CRegKey
> #include <atlimpl.cpp>    //For CRegKey

>  unsigned long lSize;
>  long errcode;
>  CRegKey theKey;
>  CString key = _T("SOFTWARE\\..<blahblah>.\\Image-Pro Plus 4.0");
>  CString myPath;
>  CString older;
>  CString newer;

> if (ERROR_SUCCESS == theKey.Open(HKEY_LOCAL_MACHINE, key,
> KEY_ALL_ACCESS))
> {
> //Note: Opens Key fine.....

> errcode = theKey.QueryValue(myPath.GetBuffer(_MAX_PATH),
> _T("LocalRootPath"), &lSize);

> //errorcode==ERR_INVAL_PARAM    HELP!!!

> if (errcode == ERROR_SUCCESS)
> //Never get here...
>  {
>   myPath.ReleaseBuffer(lSize);
>   older = myPath + "\\mccapt32.bak";
>   newer = myPath + "\\mccapt32.dll";
>   rename( older, newer );
>   theKey.Close();
>  }

The size parameter in CRegKey::QueryValue is used for input as well as
output -- on input you need to initialize the variable with the size of
the buffer (so that QueryValue won't overflow it) -- on output it will
be set to the actual length of the value returned.  So, try something
like this:

        lSize = _MAX_PATH;
        errcode = theKey.QueryValue(
                myPath.GetBuffer(_MAX_PATH),
                _T("LocalRootPath"),
                &lSize);

-- Thomas Brown



Mon, 04 Mar 2002 03:00:00 GMT  
 CRegKey::QueryValue not working

Set the lSize to _MAX_PATH prior to QueryValue call().

HTH,
John Joelle Cruz


  Hi,
  I'm trying to write a custom DLL for uninstallation that renames a file.  I'm using CRegKey to get the path of the file I need to rename, the problem arises when I use CRegKey::QueryValue.  Instead of returning the proper queried string, it returns nothing, and gives an error code 87, which I believe is ERROR_INVALID_PARAMETER.  However, I've quintuple checked my parameters and they are all of the correct type. Any help would be appreciated, my code is listed below:

  #include <afx.h>    //For CString
  #include <atlbase.h>    //For CRegKey
  #include <atlimpl.cpp>    //For CRegKey

   unsigned long lSize;
   long errcode;
   CRegKey theKey;
   CString key = _T("SOFTWARE\\..<blahblah>.\\Image-Pro Plus 4.0");
   CString myPath;
   CString older;
   CString newer;

  if (ERROR_SUCCESS == theKey.Open(HKEY_LOCAL_MACHINE, key, KEY_ALL_ACCESS))
  {
  //Note: Opens Key fine.....

  errcode = theKey.QueryValue(myPath.GetBuffer(_MAX_PATH), _T("LocalRootPath"), &lSize);

  //errorcode==ERR_INVAL_PARAM    HELP!!!

  if (errcode == ERROR_SUCCESS)
  //Never get here...
   {
    myPath.ReleaseBuffer(lSize);
    older = myPath + "\\mccapt32.bak";
    newer = myPath + "\\mccapt32.dll";
    rename( older, newer );
    theKey.Close();
   }

  Any Ideas????

  Thanks :)



Mon, 04 Mar 2002 03:00:00 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Error with Registry, CRegKey::QueryValue

2. How to use CRegKey::QueryValue

3. CRegKey works differently on NT/98?

4. C++/ATL/ADO - Intellisense not working (statement completion options) not working

5. Why do I get the error 234 when calling RegQueryValueEx or CRegKey::QueryValue?

6. QueryValue function

7. this code works on SGI does not work on linux

8. CMap Lookup not working (at least I cannot get it to work)

9. Program not work at release mode but work at debug mode

10. GetPrivateProfileSectionNames not working in 98 or ME but does work in 2000

11. Window NT BitMap Works Windows95 BitMap Does not Work

12. Not operator NOT working (!)

 

 
Powered by phpBB® Forum Software