CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Apr 1999
    Posts
    4

    Odd Problem with CRegKey

    I am using an ATL-derived Inproc COM server in a project, and I am trying to compile a release build. I am using the "Release Min-Dependency" build. The following is the code in question:

    CRegKey regkey;
    regkey.Open(HKEY_LOCAL_MACHINE, "DATAFILES");
    TCHAR path[MAX_PATH];
    DWORD count;
    regkey.QueryValue(path, "Install Folder", &count);

    When I run in Debug mode, this code works fine. When I am running in Release-MinDependancy, The "path" variable is empty the first time, but after stepping through the "QueryValue" line, if I set the next statement back to the QueryValue function call, it works the second time around.

    Also, hardcoding the "path" variable allows my software to work correctly. However, this variable needs to be read by the registry, as my software is dependant on the location of another software package.

    In order to step through this release build, I used some of the techniques in the Debug section of this website.

    Any ideas?? (calling QueryValue twice isn't a good fix... )

    Thanks in advance,
    Kevin


  2. #2
    Guest

    Re: Odd Problem with CRegKey

    Try setting the count to the size of the buffer before making the call.
    regkey.queryvalue seems to call RegQueryValueEx which expects to know the size of the buffer. Many registry key functions take the buffer size as an input argument then change it to the size actually supplied when they return. It's easy to get caught out by that, especially in a loop where you can forget to set it back on each iteration.

    If I'm right then the documentation on QueryValue at V5 is wrong so you can blame MS, though checking the status code returned would probably have said something like "buffer too small" as a hint.

    Cheers,
    Roger




Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured