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

A question on RegOpenKeyExW

51 views
Skip to first unread message

T

unread,
Dec 27, 2019, 3:57:57 AM12/27/19
to
Hi All,

Four questions on lpSubKey.

I am trying to code the following in Raku's (Perl 6's)
NativeCall:

https://docs.microsoft.com/en-us/windows/win32/api/winreg/nf-winreg-regopenkeyexw

C++
LSTATUS RegOpenKeyExW(
HKEY hKey,
LPCWSTR lpSubKey,
DWORD ulOptions,
REGSAM samDesired,
PHKEY phkResult
);

lpSubKey
The name of the registry subkey to be opened.

My goal is to read the value of:


[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System]

"EnableLUA"=dword:00000000

But first I have to open the key.

1) am I opening

\Microsoft\Windows\CurrentVersion\Policies\System
or
\Microsoft\Windows\CurrentVersion\Policies\System\EnableLUA

2) forward slashes or back slashes?

3) does it use a starting slash?

4) does it use an ending slash?

Many thanks,
-T

red floyd

unread,
Dec 27, 2019, 4:03:22 AM12/27/19
to
On 12/27/19 12:57 AM, T wrote:
> Hi All,
>
> Four questions on lpSubKey.
>
> I am trying to code the following in Raku's (Perl 6's)
> NativeCall:
>
> https://docs.microsoft.com/en-us/windows/win32/api/winreg/nf-winreg-regopenkeyexw
>
>
>     C++
>     LSTATUS RegOpenKeyExW(
>       HKEY    hKey,
>       LPCWSTR lpSubKey,
>       DWORD   ulOptions,
>       REGSAM  samDesired,
>       PHKEY   phkResult
>     );
>
>     lpSubKey
>     The name of the registry subkey to be opened.
>
[redacted]

ISO C++ does not say anyting about "RegOpenKeyExW" or a "Registry".

Please ask your question in a Windows group, rather than here.

Bonita Montero

unread,
Dec 27, 2019, 4:35:39 AM12/27/19
to
When Qt-questions are appropriate here, this is also o.k..
Hrhr. ;-)

T

unread,
Dec 27, 2019, 6:08:46 AM12/27/19
to
On 2019-12-27 00:57, T wrote:
> Hi All,
>
> Four questions on lpSubKey.
>
> I am trying to code the following in Raku's (Perl 6's)
> NativeCall:
>
> https://docs.microsoft.com/en-us/windows/win32/api/winreg/nf-winreg-regopenkeyexw
>
>
>     C++
>     LSTATUS RegOpenKeyExW(
>       HKEY    hKey,
>       LPCWSTR lpSubKey,
>       DWORD   ulOptions,
>       REGSAM  samDesired,
>       PHKEY   phkResult
>     );
>
>     lpSubKey
>     The name of the registry subkey to be opened.
>
> My goal is to read the value of:
>
>
> [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System]
>
>
>     "EnableLUA"=dword:00000000
>
> But first I have to open the key.


Figured it out.

> 1) am I opening
>
>     \Microsoft\Windows\CurrentVersion\Policies\System

The above

> or
>     \Microsoft\Windows\CurrentVersion\Policies\System\EnableLUA
>
> 2) forward slashes or back slashes?

Back slashes

>
> 3) does it use a starting slash?

No


> 4) does it use an ending slash?

No

> Many thanks,
> -T


David Brown

unread,
Dec 27, 2019, 8:53:08 AM12/27/19
to
On 27/12/2019 12:08, T wrote:
> On 2019-12-27 00:57, T wrote:

<snip>

> Figured it out.
>
Well done for posting the answer you found once you figured it out
yourself - few people do that.

But this is a group for C++ programming in general, and discussions
about the language. It is not really for application programming, and
it is certainly not for such platform specific details. You are asking
about Windows programming - the language is incidental. You would get
far better results from asking in a Windows-specific group or forum.
Posting here, you are more likely to get complaints than help.

If you want to discuss or ask about C++, then of course your posts would
be welcome.

Manfred

unread,
Dec 27, 2019, 10:06:06 AM12/27/19
to
On 12/27/2019 2:52 PM, David Brown wrote:
> On 27/12/2019 12:08, T wrote:
>> On 2019-12-27 00:57, T wrote:
>
> <snip>
>
>> Figured it out.
>>
> Well done for posting the answer you found once you figured it out
> yourself - few people do that.
>
> But this is a group for C++ programming in general, and discussions
> about the language. It is not really for application programming, and
> it is certainly not for such platform specific details. You are asking
> about Windows programming - the language is incidental.

Moreover, this question is about a Windows API, which is in C, not C++.
And how to call it from Perl. Long live polyglots!

T

unread,
Dec 27, 2019, 4:27:41 PM12/27/19
to
On 2019-12-27 05:52, David Brown wrote:
> Well done for posting the answer you found once you figured it out
> yourself - few people do that.

I think it is kind of rude to let people put time in
figuring out something for you when you have already
done it.

I also make sure and thank everyone for their help and
give feedback when useful.

T

unread,
Dec 27, 2019, 4:31:35 PM12/27/19
to
On 2019-12-27 07:05, Manfred wrote:
> Moreover, this question is about a Windows API, which is in C, not C++.
> And how to call it from Perl. Long live polyglots!

Hi Mansfred,

If you look at

https://docs.microsoft.com/en-us/windows/win32/api/winreg/nf-winreg-regopenkeyexw

You will find a definition for C++, not C, unless
this is a terrible misprint of M$'s part, which I
would not put past them.

C++
LSTATUS RegOpenKeyExW(
HKEY hKey,
LPCWSTR lpSubKey,
DWORD ulOptions,
REGSAM samDesired,
PHKEY phkResult
);

As far as calling it from Raku/Perl6, that is a migraine I
would not wish on anyone. Believe it or not, this group is
about 5 times more helpful with me configuring the
proper data structures for Raku's NativeCall. Didn't
think you guys were that smart, did you!

-T

red floyd

unread,
Dec 27, 2019, 6:35:21 PM12/27/19
to
Qt is also off topic. Please read the FAQ.

Bonita Montero

unread,
Dec 28, 2019, 1:26:15 AM12/28/19
to
I've never seen complaints against Qt-questions.
And I've also never seen a FAQ.

Alf P. Steinbach

unread,
Dec 28, 2019, 1:42:37 AM12/28/19
to
On 28.12.2019 07:26, Bonita Montero wrote:
>
> [snip]
> And I've also never seen a FAQ.

The C++ FAQ now resides at

<url: https://isocpp.org/faq>

It's no longer specific to this group: the clc++-specific material has
been edited out of Marshall Cline's original FAQ.

That material is however still present in Dietmar Kuehl's mirror (and
other mirrors, there were a host of them once) of the original FAQ, at

<url: http://www.dietmar-kuehl.de/mirror/c++-faq/>


- Alf

Bonita Montero

unread,
Dec 28, 2019, 1:45:19 AM12/28/19
to
>> [snip]
>> And I've also never seen a FAQ.

> The C++ FAQ now resides at
> <url: https://isocpp.org/faq>
> It's no longer specific to this group: the clc++-specific material has
> been edited out of Marshall Cline's original FAQ.
> That material is however still present in Dietmar Kuehl's mirror (and
> other mirrors, there were a host of them once) of the original FAQ, at
> <url: http://www.dietmar-kuehl.de/mirror/c++-faq/>

A FAQ that is valid for a newsgroup is regulary posted on this.

Alf P. Steinbach

unread,
Dec 28, 2019, 1:59:37 AM12/28/19
to
It used to be posted, by Marshall.

Unfortunately he is now old and I would guess, not in best of health. He
essentially passed the FAQ maintenance over to Herb, Bjarne and Andrei.
And they removed the clc++-specific stuff and don't post the FAQ.

Dietmar Kuehls mirror of the original FAQ is the closest to a FAQ for
the group, because it was the FAQ for the group. Unlike many other
Usenet groups there was never a /charter/ for clc++, but re the original
discussion up-thread about Qt and Windows it's perhaps relevant that the
now defunct moderated sister group clc++m was created due to a too large
influx of Windows-specific postings in clc++, so that a group for more
pure C++ was needed -- a high s/n ratio is strongly desired. Alas, like
the FAQ postings, the group charter infrastructure has just ceased
functioning so the group will never get an official charter.

- Alf

Paavo Helde

unread,
Dec 28, 2019, 4:39:20 AM12/28/19
to
On 27.12.2019 23:31, T wrote:
> On 2019-12-27 07:05, Manfred wrote:
>> Moreover, this question is about a Windows API, which is in C, not C++.
>> And how to call it from Perl. Long live polyglots!
>
> Hi Mansfred,
>
> If you look at
>
> https://docs.microsoft.com/en-us/windows/win32/api/winreg/nf-winreg-regopenkeyexw
>
>
> You will find a definition for C++, not C, unless
> this is a terrible misprint of M$'s part, which I
> would not put past them.
>
> C++
> LSTATUS RegOpenKeyExW(
> HKEY hKey,
> LPCWSTR lpSubKey,
> DWORD ulOptions,
> REGSAM samDesired,
> PHKEY phkResult
> );

The Win32 API is defined in C, but the same declaration can be used in
C++. So this declaration should actually be labelled "C and C++", but MS
has helpfully simplified it to "C++", for more user friendliness no doubt.

Note it's called "C++" not as opposed to "C", but as opposed to "Visual
Basic" and "C#".

> As far as calling it from Raku/Perl6, that is a migraine I
> would not wish on anyone. Believe it or not, this group is
> about 5 times more helpful with me configuring the
> proper data structures for Raku's NativeCall. Didn't
> think you guys were that smart, did you!

As the Win32 API is defined in C, I believe you cannot use it easily or
reliably from other languages without learning at least a bit of C
first. Especially regarding the pointers. Most parameters in the above
declaration are disguised pointers.


Alf P. Steinbach

unread,
Dec 28, 2019, 6:10:27 AM12/28/19
to
On 28.12.2019 10:39, Paavo Helde wrote:
> [snip]
> As the Win32 API is defined in C, I believe you cannot use it easily or
> reliably from other languages without learning at least a bit of C
> first. Especially regarding the pointers. Most parameters in the above
> declaration are disguised pointers.

A (very) small part of the API is written for use in scripting
languages. E.g. there's a dictionary, a text file class, and a scripting
language interface to the Windows File Explorer. And I believe the only
message box with a timeout offered by the API, resides in this part.

Also this part is no doubt defined in C, but the abstraction level
presented in the documentation is as a set of OLE Automation classes.

OLE Automation classes are easily consumed from scripting languages with
Windows bindings, and they can be (rather laboriously) defined in C. So
that's an example where C code can be easily consumed at the scripting
level, although this is C code especially crafted for the purpose.
Another and more portable example is the Python C interface, which can
consume most any C code whatsoever.

- Alf

Bonita Montero

unread,
Dec 28, 2019, 6:48:41 AM12/28/19
to
> As the Win32 API is defined in C, ...

There are a lot of IDispatch COM-APIs which can be easily used
in a scripting-language.

Manfred

unread,
Dec 28, 2019, 12:14:45 PM12/28/19
to
On 12/27/19 10:31 PM, T wrote:
> On 2019-12-27 07:05, Manfred wrote:
>> Moreover, this question is about a Windows API, which is in C, not C++.
>> And how to call it from Perl. Long live polyglots!
>
> Hi Mansfred,
>
> If you look at
>
> https://docs.microsoft.com/en-us/windows/win32/api/winreg/nf-winreg-regopenkeyexw
>
>
> You will find a definition for C++, not C, unless
> this is a terrible misprint of M$'s part, which I
> would not put past them.

As Paavo replied, C++ in their docs is opposed to VB and C#, not C
(being Visual C++, Visual Basic and C# probably their most popular
development products).
Technically, for the purpose of that API, C is a subset of C++, so it is
not incorrect.

A further confirmation that it is a C API is that windows headers
declare its functions as 'extern "C"' when compiled in C++ code, so that
C++ can transparently link to the API.

One relevant difference (between a C and C++ API) for interfacing with
other languages is that in order to allow for function overloading, C++
would require its exported symbol names to be mangled, while C does not.

>
>     C++
>     LSTATUS RegOpenKeyExW(
>       HKEY    hKey,
>       LPCWSTR lpSubKey,
>       DWORD   ulOptions,
>       REGSAM  samDesired,
>       PHKEY   phkResult
>     );

(A side note about the 'W' suffix (or 'A'): When applicable, Windows API
functions come in two variants for ASCII and wide char (Unicode)
strings; the companion function of the above is RegOpenKeyExA that
handles ASCII strings. The documentation often refers to both
collectively as RegOpenKeyEx, while the DLL exported function names are
RegOpenKeyExA and RegOpenKeyExW)

>
> As far as calling it from Raku/Perl6, that is a migraine I
> would not wish on anyone.  Believe it or not, this group is
> about 5 times more helpful with me configuring the
> proper data structures for Raku's NativeCall.  Didn't
> think you guys were that smart, did you!

I am not an expert in Perl, but I would expect its documentation to give
detailed information on how its runtime calls shared library functions.
In addition, as Paavo said, some knowledge of C is also required.

>
> -T
>

Richard

unread,
Jan 15, 2020, 4:46:06 PM1/15/20
to
[Please do not mail me a copy of your followup]

"Alf P. Steinbach" <alf.p.stein...@gmail.com> spake the secret code
<qu7d6p$433$1...@dont-email.me> thusly:

>On 28.12.2019 10:39, Paavo Helde wrote:
>> [snip]
>> As the Win32 API is defined in C, I believe you cannot use it easily or
>> reliably from other languages without learning at least a bit of C
>> first. Especially regarding the pointers. Most parameters in the above
>> declaration are disguised pointers.
>
>A (very) small part of the API is written for use in scripting
>languages. [...]

Not that it's relevant to C++, but a huge portion of the API is
available to scripting languages because you can create COM objects
and huge chunks of the Win32 services are exposed as COM objects.

Now here's where C++ comes in. If you want to access a chunk of the
Win32 API from script, but there isn't an existing COM object that
exposes that API, you can easily write such a COM object in C++.

Also, did you know that Windows ships with a scriptable JavaScript
engine, complete with a visual debugger? No need to keep writing ugly
DOS batch scripts, just use JavaScript. It's been shipping with
Windows for over 15 years, yet developers continue to remain unaware
of it.
--
"The Direct3D Graphics Pipeline" free book <http://tinyurl.com/d3d-pipeline>
The Terminals Wiki <http://terminals-wiki.org>
The Computer Graphics Museum <http://computergraphicsmuseum.org>
Legalize Adulthood! (my blog) <http://legalizeadulthood.wordpress.com>
0 new messages