GithubHelp home page GithubHelp logo

fcccode / winreg Goto Github PK

View Code? Open in Web Editor NEW

This project forked from giovannidicanio/winreg

0.0 0.0 0.0 29 KB

Convenient high-level C++ wrappers around Windows Registry Win32 APIs

License: MIT License

C++ 100.00%

winreg's Introduction

WinReg v1.1

High-level C++ Wrappers Around Low-level Windows Registry C-interface APIs

by Giovanni Dicanio

The Windows Registry C-interface API is very low-level and hard to use.

I developed some C++ wrappers around this low-level Win32 API, to raise the semantic level, using C++ classes like std::wstring, std::vector, etc. instead of raw C-style buffers and low-level mechanisms.

For example, the REG_MULTI_SZ registry type associated to double-NUL-terminated C-style strings is handled using a much easier higher-level vector<wstring>. My C++ code does the translation between high-level C++ STL-based stuff and low-level Win32 C-interface APIs.

Moreover, Win32 error codes are translated to C++ exceptions.

The Win32 registry value types are mapped to C++ higher-level types according the following table:

Win32 Registry Type C++ Type
REG_DWORD DWORD
REG_QWORD ULONGLONG
REG_SZ std::wstring
REG_EXPAND_SZ std::wstring
REG_MULTI_SZ std::vector<std::wstring>
REG_BINARY std::vector<BYTE>

I developed this code using Visual Studio 2015 with Update 3. The code compiles cleanly at /W4 in both 32-bit and 64-bit builds.

The library's code is contained in a reusable header-only WinReg.hpp file.

WinRegTest.cpp contains some demo/test code for the library: check it out for some sample usage.

The library exposes two main classes:

  • RegKey: a tiny efficient wrapper around raw Win32 HKEY handles
  • RegException: an exception class to signal error conditions

There are many member functions inside the RegKey class, that wrap raw Win32 registry C-interface APIs in a convenient C++ way.

For example, you can simply open a registry key and get registry values with C++ code like this:

RegKey key{ HKEY_CURRENT_USER, L"SOFTWARE\\Connie" };
DWORD dw = key.GetDwordValue(L"SomeDwordValue");
wstring s = key.GetStringValue(L"SomeStringValue");

Or you can enumerate all the values under a key with this simple code:

auto values = key.EnumValues();

The library stuff lives under the winreg namespace.

See the WinReg.hpp header for more details and documentation.

winreg's People

Contributors

giovannidicanio avatar

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.