On Wed, Jan 29, 2020 at 03:44 Tobias Boege <t...@taboege.de> wrote:

> On Tue, 28 Jan 2020, ToddAndMargo via perl6-users wrote:
> > This all came up when I tried to match
> >
> >       RegSetValueExW(
> >           _In_ HKEY hKey,
> >           _In_opt_ LPCWSTR lpValueName,
> >           _Reserved_ DWORD Reserved,
> >           _In_ DWORD dwType,
> >           _In_reads_bytes_opt_(cbData) CONST BYTE * lpData,
> >           _In_ DWORD cbData
> >
> > where CbData can either be a UTF little endian C string,
> > terminated by a nul or a four byte little endian
> > unsigned integer (no two's complement allowed) depending
> > on the value of lpValueName (REG_SZ, REG_DWORD, etc.)
> >
> > I wound up doing this:
> >
> > subset StrOrDword where Str | UInt;
> > sub WinRegSetValue( WinRegHives $Hive, Str $SubKey, Str $KeyName,
> ValueNames
> > $ValueType, StrOrDword $ValueData, Bool $Debug = False )
> >                     returns DWORD is export( :WinRegSetValue ) {
>
> Are you really 100% sure that you interpreted this API correctly? I see how
> a DWORD cbData can be a four-byte unsigned integer: it gives the length of
> lpData in bytes, as documented [1].


>
> But then a DWORD is 4 bytes long. Reusing these 4 bytes for an alternative
> interface where you may pass a UTF-whatever string that is at most 4 bytes
> encoded, including the NUL terminator... seems too insane.


I was going to ask about that (but it seemed out of Raku-world, and I don’t
even play someone who knows about Windows on TV), but, okay, I’ll bite...
what are some examples of the precisely 3-byte + 32-bit null UTF strings
you imagine being encoded by this interface? I have never heard of such a
small fixed-width UTF data structure before because it’s just so bizarre,
and then mandating a null termination so you lose the 4th byte that would
make this structure at least somewhat coherent as a UCS-4 codepoint...
since there’s no such thing as UTF-24, I assume this is three UTF-8 bytes
packed (which I guess is what you mean by “little endian C string”, but
that becomes at best ill-defined abutted next to “UTF”)... But, what on
earth is it being used for?

I’m fascinated, in the way a cat is fascinated by a snake....

Reply via email to