microsoft / wil

Windows Implementation Library

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Some questions about wil::reg

petercoin opened this issue · comments

Hello,
I have taken a look at wil::reg and have a few questions that I was hoping you could clarify:

  1. Is there a specific reason for using PCWSTR for subkey and value_name instead of std::wstring?
  2. In reference to the Remarks provided for RegOpenKeyExW, would it be more appropriate to use RegOpenCurrentUser for HKEY_CURRENT_USER?

Thank you for your assistance and insights. Looking forward to your response.

Best regards.

Regarding your first question:

  • Not all consumers of WIL have access to the STL, so any code that uses STL types must be guarded, limiting their usefulness. This has a cascading effect where any functions using those functions must also be guarded
  • For input, none of the Windows APIs accept std::basic_string, so using that for input params would needlessly require consumers to construct one, wasting time and memory
  • For output, std::basic_string is a terrible API to use for output buffers due to the lack of some form of uninitialized_resize that would allow us to change the underlying buffer size without needlessly writing zeros to the soon-to-be overwritten or discarded memory

due to the lack of some form of uninitialized_resize

For the sake of completion: C++23 has introduced resize_and_overwrite, although this doesn't help with older C++ standards of course.

Huh, good to know, I missed that. But yeah, the C++ version requirement (the Windows codebase is still on C++17 as the default AFAIK) and all other issues still apply.