Simon Rozman 96197da77e Introduce NormalizeString<>()
Signed-off-by: Simon Rozman <simon@rozman.si>
2021-03-25 10:33:24 +01:00
2020-02-06 15:34:11 +01:00
2021-03-25 08:32:57 +01:00
2019-01-21 10:54:38 +01:00
2020-02-08 08:06:31 +01:00
2020-02-08 08:37:23 +01:00
2020-02-08 07:52:08 +01:00
2020-02-08 07:52:08 +01:00

WinStd Build status

Provides additional templates and function helpers for Windows API using Standard C++

Features

Lightweight Classes

...to simplify Windows allocated memory and resources focused on their release to prevent leakage

The classes provide unified create methods and free destructors. They are like smart-pointers for various Windows resources. Once created, you use the class instance as a snap-in replacement for pointers/handles parameters in the standard Win32 API functions.

Example

// Load and set icon.
winstd::library lib_shell32;
if (lib_shell32.load(_T("shell32.dll"), NULL, LOAD_LIBRARY_AS_DATAFILE | LOAD_LIBRARY_AS_IMAGE_RESOURCE))
    m_note_icon->SetIcon(wxLoadIconFromResource(lib_shell32, MAKEINTRESOURCE(48)));

Functions and Templates

...to extend standard Win32 API functions for variable-size outputs

Different Win32 API functions have different ways of returning variable-sized data. Getting tired of carefully studying MSDN for each particular Win32 API function how to preallocate the output memory correctly? We too...

WinStd provides a subset of Win32 API identically named functions (C++ polymorphism to the rescue), where one can use std::string, std::wstring, std::vector<> etc. as an output parameter. WinStd handles all the dirty work with memory allocation for you, so you can focus on your code.

Example

// Encode response as OEM.
std::string response;
WideCharToMultiByte(CP_OEMCP, 0, L"Copyright \u00A9 2017", response, NULL, NULL);
std::cout << response.c_str() << std::endl;

String Formatters

...for those situations where one must quckly compose a temporary string using sprintf() or FormatMessage()

Example

if (dwMaxSendPacketSize < sizeof(EapPacket))
    throw std::invalid_argument(
        winstd::string_printf(
            "Maximum packet size too small (minimum: %zu, available: %u).",
            sizeof(EapPacket) + 1,
            dwMaxSendPacketSize));

Building

Requires:

  • Microsoft Visual Studio 2017-2019
  • ..\..\include folder with the following files to customize building process for individual applications (optional):
    • Debug.props
    • Release.props
    • ARM64.props
    • x64.props
    • Win32.props

Usage

  1. Clone the repository into your solution folder.
  2. Add the appropriate build\WinStd-<version>.vcxproj to your solution.
  3. Add WinStd's include folder to Additional Include Directories in your project's C/C++ settings.
  4. Add a new reference to WinStd project from your project's common properties.
  5. Include .h files from WinStd as needed:
#include <WinStd/Shell.h>
#include <string>
#include <iostream>

void main()
{
  std::wstring path;
  PathCanonicalize(path, _T("C:\\Windows\\Temp\\test\\.."));
  std::cout << path.c_str() << std::endl;
}

More examples and use-cases can be found in GÉANTLink and ZRCola projects source code. They make heavy use of WinStd.

Description
C++ Wrappers for Windows API
Readme MIT 14 MiB
Languages
C++ 99.8%
C 0.2%