Article View: borland.public.cppbuilder.nativeapi
Article #15739Re: RegQueryValueEx problem
From: user
Date: Wed, 18 Jun 2003 03:44
Date: Wed, 18 Jun 2003 03:44
30 lines
2295 bytes
2295 bytes
Remy Lebeau (TeamB) wrote:
>
>>has anyone a RegQuery-example? I've got problems
>>executing the following code: The result shows me, that
>>the program cannot find the specified registry key, but
>>it is there, as regedit shows to me. I'm thankful for any help!
>
>
> You should not be reading the "Shell Folders" manually. MS has a separate
> SHGetSpecialFolderLocation() function for exactly that purpose instead. Use
> the CSIDL_PERSONAL flag to request the value you're trying to get.
>
>
>>if(RegQueryValueEx(regh, regkey, NULL, NULL, buffer, buffsize + 1) ==
>
> ERROR_SUCCESS) {
>
> Where is buffer and bufsize defined? They are not in your code snippet at
> all. What are they defined as exactly? What is the actual return value of
> RegQueryValueEx() when it fails? What is the return value of
> GetLastError()?
>
> Also, you have a resource leak as you are calling RegCloseKey() only if
> RegQueryKeyEx() succeeds. If it fails, you are not closing the key at all.
>
Also, the final parameter is supposed to be a pointer to a DWORD that
contains the size of the buffer. It appears that you are passing the
size itself. (In any case, adding 1 to the pointer or to the size of the
buffer seems dubious.)
Technical Details
Message-ID:
<3EEFE033.6060605@domain.invalid>Path:
arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-04!sn-xit-01!sn-xit-06!sn-xit-09!supernews.com!news.maxwell.syr.edu!newsfeed.wirehub.nl!news.kweb.on.ca!KWeb!newsgroups.borland.com!not-for-mailReferences:
<3eef5413@newsgroups.borland.com> <3eef5db8$1@newsgroups.borland.com>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 10cc67,5800567a1464c960 X-Google-Attributes: gid10cc67,public X-Google-ArrivalTime: 2003-06-17 20:51:33 PST Message-ID: <3EEFE033.6060605@domain.invalid> Date: Tue, 17 Jun 2003 23:44:51 -0400 From: user@domain.invalid User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.0.2) Gecko/20030208 Netscape/7.02 X-Accept-Language: en-us, en MIME-Version: 1.0 Newsgroups: borland.public.cppbuilder.nativeapi Subject: Re: RegQueryValueEx problem References: <3eef5413@newsgroups.borland.com> <3eef5db8$1@newsgroups.borland.com> Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit NNTP-Posting-Host: 68.162.160.95 X-Trace: newsgroups.borland.com 1055907918 68.162.160.95 (17 Jun 2003 20:45:18 -0700) Lines: 31 Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-04!sn-xit-01!sn-xit-06!sn-xit-09!supernews.com!news.maxwell.syr.edu!newsfeed.wirehub.nl!news.kweb.on.ca!KWeb!newsgroups.borland.com!not-for-mail