Code Monkey home page Code Monkey logo

Comments (3)

GiovanniDicanio avatar GiovanniDicanio commented on August 24, 2024

One option could be trying opening the subkey with RegKey::TryOpen(), and then check the result code.
If the result code is 2 (ERROR_FILE_NOT_FOUND), that means that the subkey doesn't exist.
If the result code is 0 (ERROR_SUCCESS), that means that the subkey exists and was correctly opened.

For example:

// Try open the subkey for read
auto result = key.TryOpen(HKEY_CURRENT_USER, LR"(SOFTWARE\Classes\ms)", KEY_READ);
if (result.Code() == ERROR_FILE_NOT_FOUND)
{
    // Doesn't exist
}

from winreg.

SnowMeteors avatar SnowMeteors commented on August 24, 2024

Thank you, I have reviewed the source code and suggest using std::wstring_view instead of const std::wstring & in source code

from winreg.

GiovanniDicanio avatar GiovanniDicanio commented on August 24, 2024

Using std::wstring_view instead of const std::wstring& in that context would be really bad and a source of lots of bugs. In fact, typically Win32 C-style APIs (or at least those used in my code), expect PCWSTR as (Unicode UTF-16) input string parameters. PCWSTR is a _Null_terminated_ const wchar_t*; on the other hand, std::wstring_views are not guaranteed to be null terminated! So using them as you suggest would cause lots of (subtle) bugs. Things might be different if the C++ standard library would provide a proper null-terminated version of string views.

from winreg.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.