Friday, December 27, 2019

Digest for comp.lang.c++@googlegroups.com - 25 updates in 7 topics

T <T@invalid.invalid>: Dec 27 12:57AM -0800

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 <no.spam@its.invalid>: Dec 27 01:03AM -0800

On 12/27/19 12:57 AM, T wrote:
>     );
 
>     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 <Bonita.Montero@gmail.com>: Dec 27 10:35AM +0100


> [redacted]
> ISO C++ does not say anyting about "RegOpenKeyExW" or a "Registry".
> Please ask your question in a Windows group, rather than here.
 
When Qt-questions are appropriate here, this is also o.k..
Hrhr. ;-)
T <T@invalid.invalid>: Dec 27 03:08AM -0800

On 2019-12-27 00:57, T wrote:
 
> [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
 
David Brown <david.brown@hesbynett.no>: Dec 27 02:52PM +0100

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 <noname@add.invalid>: Dec 27 04:05PM +0100

On 12/27/2019 2:52 PM, David Brown wrote:
> 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!
 
You would get
T <T@invalid.invalid>: Dec 27 01:27PM -0800

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 <T@invalid.invalid>: Dec 27 01:31PM -0800

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
T <T@invalid.invalid>: Dec 27 01:24PM -0800

Hi All,
 
In C++, when you make a call to Windows Kernel32.dll
and it wants a NULL for one or more of its parameters,
what exactly is the structure of a NULL? A 32 bit
word full of zeros?
 
Many thanks,
-T
"Alf P. Steinbach" <alf.p.steinbach+usenet@gmail.com>: Dec 27 05:07AM +0100

On 26.12.2019 16:55, Bo Persson wrote:
 
> And for the most vexing parse - cin is a value, but it *could* also be
> the name of a parameter for a (hypothetical) words function. So parsing
> a declaration wins!
 
Thanks.
 
I wanted to see how conventional C++17 code fares against the C++20
Range-based pipeline stuff in the linked to article
 
https://medium.com/@vgasparyan1995/a-little-bit-of-code-c-20-ranges-c6a6f7eae401
 
So the code below is what I came up with. It relies on two of my own
libraries for some small stuff that avoids a details mess.
 
To me this conventional code is easier to read and to reason about than
the Ranges code, but to the author of that article it's evidently
opposite. I suspect that most of those who love Ranges are of a
mathematical inclination, and that it reminds them of functional
programming. Maybe.
 
 
--------------------------------------------------------
 
// Read a file of text, determine the n most frequently used words, and
print out a sorted
// list of those words along with their frequencies.
//
//
https://medium.com/@vgasparyan1995/a-little-bit-of-code-c-20-ranges-c6a6f7eae401
 
// Assuming
// * ASCII text.
 
#include <cppx-core-language/all.hpp> //
https://github.com/alf-p-steinbach/cppx-core-language
#include <cpp/all.hpp> //
https://github.com/alf-p-steinbach/Cpp-Header-Collections
 
namespace app {
$use_std( cin, cout, endl, quoted, string, string_view, vector, min );
template< class Key, class Value > using Map_ =
std::unordered_map<Key, Value>;
 
$use_cppx( Truth, Size, Index, hopefully, fail, span_of, string_to_ );
namespace ascii = cppx::ascii;
using namespace cppx::syntax; // String assembly via
"<<".
 
auto sans_punctuation( const string_view& s )
-> string
{
string result;
for( const char ch: s ) {
if( not ascii::is_punctuation( ch ) ) {
result += ch;
}
}
return result;
}
 
auto words_and_counts()
-> auto
{
Map_<string, Size> result;
using In_it = std::istream_iterator<string>;
for( const string& s: span_of( In_it( cin ), In_it() ) ) {
const string word = ascii::to_lowercase( sans_punctuation(
s ) );
if( word.length() != 0 ) {
++result[word];
}
}
return result;
}
 
struct Word_info { string text; Size count; };
 
auto order_by_decreasing_counts( const Word_info& a, const
Word_info& b )
-> Truth
{ return a.count > b.count; }
 
void run( const vector<string_view>& command_parts )
{
hopefully( command_parts.size() == 2 )
or fail( "Usage: "s << command_parts[0] << " N_ITEMS" );
 
const Size n = string_to_<Size>( command_parts[1] );
vector<Word_info> sorted;
for( const auto& pair: words_and_counts() ) {
sorted.push_back( {pair.first, pair.second} );
}
sort( $items_of( sorted ), order_by_decreasing_counts );
$repeat_times( min<Size>( n, sorted.size() ) ) {
cout << _i + 1 << ": "
<< quoted( sorted[_i].text ) << ' ' <<
sorted[_i].count << " time(s)"
<< endl;
}
}
} // namespace app
 
auto main( int n_args, char** args )
-> int
{
$use_std( vector, string_view, exception, cerr, endl );
try {
app::run( vector<string_view>( args, args + n_args ) );
return EXIT_SUCCESS;
} catch( const exception& x ) {
cerr << "!" << x.what() << endl;
}
return EXIT_FAILURE;
}
--------------------------------------------------------
 
- Alf
Mr Flibble <flibble@i42.removethisbit.co.uk>: Dec 27 04:38PM

On 27/12/2019 04:07, Alf P. Steinbach wrote:
 
>     $use_std( cin, cout, endl, quoted, string, string_view, vector, min );
 
Egregious (std:: preferred).
 
>     template< class Key, class Value > using Map_ =
> std::unordered_map<Key, Value>;
 
Egregious (adds nothing but obfuscation).
 
>     $use_cppx( Truth, Size, Index, hopefully, fail, span_of, string_to_ );
 
Egregious (std:: preferred).
 
>         hopefully( command_parts.size() == 2 )
>             or fail( "Usage: "s << command_parts[0] << " N_ITEMS" );
 
Egregious (adds nothing but obfuscation).
 
>         $repeat_times( min<Size>( n, sorted.size() ) ) {
 
Egregious (adds nothing but obfuscation).
 
> auto main( int n_args, char** args )
>     -> int
 
Egregious (delibarate troll or OCD).
 
>     $use_std( vector, string_view, exception, cerr, endl );
 
Egregious (std:: preferred).
 
> - Alf
 
/Flibble
 
--
"You won't burn in hell. But be nice anyway." – Ricky Gervais
"I see Atheists are fighting and killing each other again, over who
doesn't believe in any God the most. Oh, no..wait.. that never happens."
– Ricky Gervais
"Suppose it's all true, and you walk up to the pearly gates, and are
confronted by God," Bryne asked on his show The Meaning of Life. "What
will Stephen Fry say to him, her, or it?"
"I'd say, bone cancer in children? What's that about?" Fry replied.
"How dare you? How dare you create a world to which there is such misery
that is not our fault. It's not right, it's utterly, utterly evil."
"Why should I respect a capricious, mean-minded, stupid God who creates
a world that is so full of injustice and pain. That's what I would say."
"Alf P. Steinbach" <alf.p.steinbach+usenet@gmail.com>: Dec 27 08:05PM +0100

On 27.12.2019 17:38, Mr Flibble wrote:
 
> Egregious (std:: preferred).
 
Why do you prefer to repeat a bit of text ad nauseam? It's more to
write, more to read, recommended against by a number of generally
accepted guidelines like DRY, and just plain freaking dumb. So, why?
 
- Alf
boltar@nowhere.org: Dec 27 05:14PM

On Thu, 26 Dec 2019 19:52:36 +0200
>> stack is it? (Unless you use an allocator that uses alloca() or similar. And
>> good luck with that).
 
>True for some kind of containers, but std::optional is not one of those.
 
The whole point of this discussion is optionals being used inside standard
STL containers.
 
 
>> A contrived example. Now allocate optionals containing objects in a loop.
 
>You cannot refute direct evidence just be calling it "contrived" (which
>it isn't). And loops have nothing to do with how std::optional works.
 
It is contrived since any non trivial program will create and destroy
depending on processing factors. They're not predeclared beforehand so they
can be stored on the stack!
boltar@nowhere.org: Dec 27 05:17PM

On Thu, 26 Dec 2019 18:30:02 +0000
 
>Output:
>address of optional on stack: 0x7ffc35b03890
>address of optional contained value: 0x7ffc35b03890
 
Fascinating.
 
>Now will you please fuck off you deliberately obtuse idiot.
 
Now why not go write yourself a program that, oh I don't know, loads in
biological data points as the OP was talking about in a fucking loop creating
data objects as it goes and try and store them on the stack without writing
your own allocator that uses alloca() or similar API stack functions.
 
Good luck, get back to me when you're done.
Daniel <danielaparker@gmail.com>: Dec 27 09:41AM -0800


> The whole point of this discussion is optionals being used inside standard
> STL containers.
 
Then what exactly is your point? Are you suggesting that
std::vector<std::optional<T>> is inferior to some other way of storing a
collection of optional values? What other way are you thinking of?
 
Thanks,
Daniel
"Öö Tiib" <ootiib@hot.ee>: Dec 27 09:58AM -0800

> data objects as it goes and try and store them on the stack without writing
> your own allocator that uses alloca() or similar API stack functions.
 
> Good luck, get back to me when you're done.
 
How chaotic and unplanned you expect scientists to be? In planning
of their experiments they were capable to take into account even
such constraints like maximum count of rows of csv files that
Lotus 1-2-3 was capable to import. Scientists are rational people,
unlike lot of wannabe programmers. In fact I remember requirements
to help them and to warn about such things. So all arrays were
definitely possible to allocate once if not to make with static
compile-time known size.
Richard Damon <Richard@Damon-Family.org>: Dec 27 11:24AM -0500

On 12/26/19 6:20 AM, Öö Tiib wrote:
>> template and is not explicitly prohibited."
 
> Note that by your interpretation, Pavel, standard is violating itself:
> <https://en.cppreference.com/w/cpp/utility/functional/placeholders>
 
Those names are reserved for the Standard to use. There is absolutely
nothing in the Standard that prohibit it from taking a particular name
in that set and defining it for use by the user. In fact, that is one of
the reason that in C, the 'true name' for the boolean type is _Bool, as
that was a name that was reserved for the implementation, and thus
should not legally have previously appeared in any user code, so no
backwards breakage introducing it (many user applications had a type
called bool defined in many different ways). It was only by including a
specific header that the symbol bool got its now standard definition, so
old programs could stay valid as they didn't include that header and new
programs could include the header and get the nice name.
 
Note the words, "unless otherwised specified", That section you
reference specifies a particular set of symbols and how they can be used.
"Öö Tiib" <ootiib@hot.ee>: Dec 27 09:22AM -0800

On Friday, 27 December 2019 18:24:12 UTC+2, Richard Damon wrote:
 
> > Note that by your interpretation, Pavel, standard is violating itself:
> > <https://en.cppreference.com/w/cpp/utility/functional/placeholders>
 
> Those names are reserved for the Standard to use.
 
Nope. *All* *and* *every* name, including but not limited to plain and
pure profanities with and without underlines anywhere, in namespace std
or in namespaces within namespace std are reserved for the Implementation
to define or to declare by quoted above Word Of Standard. ;)
 
> There is absolutely
> nothing in the Standard that prohibit it from taking a particular name
> in that set and defining it for use by the user.
 
Sure, I totally disagree with interpretation of Paul. In fact the
placeholders I cited were as example of contradiction of his
claim B that those names may be only used by Implementation and
only in global namespace.
 
> specific header that the symbol bool got its now standard definition, so
> old programs could stay valid as they didn't include that header and new
> programs could include the header and get the nice name.
 
Yes but do not talk about what C does to those smug language lawyers of
C++ committee. Significant part of those would make the two languages
totally incompatible if only to give chance.
 
> Note the words, "unless otherwised specified", That section you
> reference specifies a particular set of symbols and how they can be used.
 
What section? I quoted first paragraph of [namespace.std] from C++17.
Thiago Adams <thiago.adams@gmail.com>: Dec 27 05:12AM -0800

On Thursday, December 19, 2019 at 12:10:57 AM UTC-3, Cholo Lennon wrote:
> the chrono Library
> https://youtu.be/adSAN282YIw?list=WL
 
> Regards
 
In my view the valuable part is here:
 
http://howardhinnant.github.io/date_algorithms.html
 
Algorithms, tests and reasoning.
Very good reference.
T <T@invalid.invalid>: Dec 26 10:48PM -0800

Hi All,
 
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
);
Return value
If the function succeeds, the return value is ERROR_SUCCESS.
 
I am getting back a 2 from RegOpenKeyExW and a 6
from RegCloseKey. (0 means success.)
 
So, I am feeding RegOpenKeyExW something it does not like.
 
Is there a list somewhere that will tell me what the
return codes mean?
 
Many thanks,
-T
Bonita Montero <Bonita.Montero@gmail.com>: Dec 27 08:09AM +0100

> 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
 
"If the function fails, the return value is a nonzero error code defined
in Winerror.h."
^^^^^^^^^^
"Öö Tiib" <ootiib@hot.ee>: Dec 26 11:13PM -0800

On Friday, 27 December 2019 08:48:18 UTC+2, T wrote:
> return codes mean?
 
> Many thanks,
> -T
 
The online docs you cite say that list is in Winerror.h and you can
also FormatMessage to get short description. What holds you back?
T <T@invalid.invalid>: Dec 26 11:49PM -0800

On 2019-12-26 23:09, Bonita Montero wrote:
 
>> https://docs.microsoft.com/en-us/windows/win32/api/winreg/nf-winreg-regopenkeyexw
 
> "If the function fails, the return value is a nonzero error code defined
> in Winerror.h."
 
Hi Bonita,
 
Found it. Thank you!
 
System Error Codes (0-499)
https://docs.microsoft.com/en-us/windows/win32/debug/system-error-codes--0-499-
 
ERROR_FILE_NOT_FOUND
 
2 (0x2)
 
The system cannot find the file specified.
 
 
ERROR_INVALID_HANDLE
 
6 (0x6)
 
The handle is invalid.
 
 
 
-T
T <T@invalid.invalid>: Dec 26 11:49PM -0800

On 2019-12-26 23:13, Öö Tiib wrote:
>> -T
 
> The online docs you cite say that list is in Winerror.h and you can
> also FormatMessage to get short description. What holds you back?
 
Found it. Thank you!
 
System Error Codes (0-499)
https://docs.microsoft.com/en-us/windows/win32/debug/system-error-codes--0-499-
"Alf P. Steinbach" <alf.p.steinbach+usenet@gmail.com>: Dec 27 01:55PM +0100

On 27.12.2019 08:09, Bonita Montero wrote:
 
> "If the function fails, the return value is a nonzero error code defined
> in Winerror.h."
>    ^^^^^^^^^^
 
In addition to the descriptions in the <winerror.h> header, the
`FormatMessage` API function produces a textual description from a
message DLL. The default message DLL has the descriptions in
`<winerror.h>` plus some more (the descriptions in the header are valid
input to the mc message compiler in order to produce a message DLL).
Some other message DLLs reside in the Windows system folder.
 
`FormatMessage` is the underlying engine of Microsoft's `errlook`
utility. Unfortunately that's a little GUI program, so it's less than
generally useful. It's been that way since the late 1990s.
 
In the command line you can use the more limited facilities of
Powershell to get a description, e.g. using a batch file like this:
 
 
--------------------------------------------------------------------
echo off
 
if "%1"=="" (
echo Usage: %0 NUMBER 1>&2
exit /b 1
)
 
if "%1"=="1" (
echo Something failed ^(could also be "Incorrect function" or
"S_FALSE"^).
) else (
powershell -command "[ComponentModel.Win32Exception] %1" 2>nul ^
|| echo "%1" must be a number. 1>&2
)
--------------------------------------------------------------------
 
 
The reason for the special treatment of code 1 is the unreasonable
convention of all extant Windows C and C++ implementations of defining
EXIT_FAILURE as code 1, when code 1 already has two meanings, widening
that ambiguity to /three/ possible meanings.
 
It's IMO just so needlessly braindead.
 
Anyway, hope this helps.
 
 
- Alf
You received this digest because you're subscribed to updates for this group. You can change your settings on the group membership page.
To unsubscribe from this group and stop receiving emails from it send an email to comp.lang.c+++unsubscribe@googlegroups.com.

No comments: