Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

::RegOpenKeyEx fails with invalid parameter error (87) unless regedit is started

1,474 views
Skip to first unread message

kamik...@gmail.com

unread,
Mar 15, 2009, 2:57:15 PM3/15/09
to
Hi folks,

A customer had some problems with our software and after some
debugging we found out that the ::RegOpenKeyEx() function fails and
return error code 87 (invalid parameter). Now the strange thing is
that when the customer has opened the regedit application, the problem
does not exist....?????

Has anyone seen this before and what whas the solution?

greetings,

Douwe

(below is the code which has the RegOpenKeyEx() call)

//----------------------------------------------------------------------------
// Function NCGenRegistry::GetString (with 'named' default)
//----------------------------------------------------------------------------
const nstring NCGenRegistry::GetString(HKEY hKey, const nstring&
crstrSubKey, const nstring& crstrValue, const nstring& crstrDefault)
{
HKEY hKey1;
nstring strValueData = crstrDefault;

if (::RegOpenKeyEx(hKey, crstrSubKey.c_str(), 0, KEY_QUERY_VALUE,
&hKey1) == ERROR_SUCCESS)
{
.....

::RegCloseKey(hKey1);
}

return strValueData;
}

Vincent Fatica

unread,
Mar 15, 2009, 5:59:45 PM3/15/09
to
Well, there's an invalid parameter. What's in these

hKey
crstrSubKey.c_str()

when the function is called?

--
- Vince

kamik...@gmail.com

unread,
Mar 15, 2009, 5:36:19 PM3/15/09
to
On 15 mrt, 22:59, Vincent Fatica <vi...@blackholespam.net> wrote:
> Well, there's an invalid parameter.  What's in these
>
>         hKey
>         crstrSubKey.c_str()
>
> when the function is called?


hKey is HKEY_CURRENT_USER
crstrSubKey is "Software\CompanyName\ProductName\3.0"

The strange thing is that this code is working on every computer
tested (including the 20 software developers working on/with this
code) but on one customer computer it fails.

It might be a problem with security or access levels on the customers
computer but I cannot figure out why the problem does not exist when
'regedit.exe' is started.

No regedit -> invalid parameter, regedit loaded -> everything goes ok
and the key can be opened and subsequently the value can be read
(with ::RegQueryValueEx).

Very, very strange.....

Tim Roberts

unread,
Mar 15, 2009, 6:13:14 PM3/15/09
to
"kamik...@gmail.com" <kamik...@gmail.com> wrote:
>
>A customer had some problems with our software and after some
>debugging we found out that the ::RegOpenKeyEx() function fails and
>return error code 87 (invalid parameter). Now the strange thing is
>that when the customer has opened the regedit application, the problem
>does not exist....?????

Are you opening a key in one of the standard hives (HKEY_LOCAL_MACHINE,
HKEY_CURRENT_USER, etc), or some weird hive?
--
Tim Roberts, ti...@probo.com
Providenza & Boekelheide, Inc.

Vincent Fatica

unread,
Mar 15, 2009, 11:25:16 PM3/15/09
to
On Sun, 15 Mar 2009 14:36:19 -0700 (PDT), "kamik...@gmail.com"
<kamik...@gmail.com> wrote:

|hKey is HKEY_CURRENT_USER
|crstrSubKey is "Software\CompanyName\ProductName\3.0"
|
|The strange thing is that this code is working on every computer
|tested (including the 20 software developers working on/with this
|code) but on one customer computer it fails.

Could it be that on that machine, the name of the key is not exactly as
expected?
--
- Vince

kamik...@gmail.com

unread,
Mar 16, 2009, 2:34:12 AM3/16/09
to
On 15 mrt, 23:13, Tim Roberts <t...@probo.com> wrote:

> "kamikaas...@gmail.com" <kamikaas...@gmail.com> wrote:
>
> >A customer had some problems with our software and after some
> >debugging we found out that the ::RegOpenKeyEx() function fails and
> >return error code 87 (invalid parameter). Now the strange thing is
> >that when the customer has opened the regedit application, the problem
> >does not exist....?????
>
> Are you opening a key in one of the standard hives (HKEY_LOCAL_MACHINE,
> HKEY_CURRENT_USER, etc), or some weird hive?
> --
> Tim Roberts, t...@probo.com
> Providenza & Boekelheide, Inc.

Its in the KEY_CURRENT_USER hive, nothing spectacular....

kamik...@gmail.com

unread,
Mar 16, 2009, 2:41:20 AM3/16/09
to
On 16 mrt, 04:25, Vincent Fatica <vi...@blackholespam.net> wrote:
> On Sun, 15 Mar 2009 14:36:19 -0700 (PDT), "kamikaas...@gmail.com"

>
> <kamikaas...@gmail.com> wrote:
>
> |hKey is HKEY_CURRENT_USER
> |crstrSubKey is "Software\CompanyName\ProductName\3.0"
> |
> |The strange thing is that this code is working on every computer
> |tested (including the 20 software developers working on/with this
> |code) but on one customer computer it fails.
>
> Could it be that on that machine, the name of the key is not exactly as
> expected?
> --
>  - Vince

I will double check this again but that would not explain why the
starting of regedit 'fixes' the problem.

In the mean time, I found a post of someone having a similar problem
back in 2005, unfortunately no solution.....

http://bytes.com/groups/c/139751-issue-regopenkeyex

Alex Blekhman

unread,
Mar 16, 2009, 3:53:02 AM3/16/09
to
<kamik...@gmail.com> wrote:
> crstrSubKey is "Software\CompanyName\ProductName\3.0"

Probably stupid question, but do you escape backslashes in the
string? Like this:

"Software\\CompanyName\\ProductName\\3.0"

Alex


0 new messages