Click to See Complete Forum and Search --> : Odd Problem with CRegKey


kmtambasc98
April 10th, 1999, 04:04 PM
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

April 13th, 1999, 02:45 AM
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