Giter Club home page Giter Club logo

casements's Introduction

Casements

The casements library adapts a few bits of the Win32 API for C++. The Casements interface avoids the need to include the troublesome Windows.h header in application code. The application should add casements/include to its list of include paths. Source files are under the casements/src directory and are built using the casements_lib Visual Studio project file. Unit tests are under casements/test and are built using the casements_test project file. The casements library depends on the Boost C++ libraries.

API Errors

Most Win32 API calls return zero if they fail. The casements::check template function can be used to test for failure. If the call was successful, the result is returned to the application. On error, a casements::error is thrown. The application can provide an "action" description that can serve as code documentation and improve the error message. For example:

HICON hicon = casements::check
  ( ::ExtractIcon(hinst, "myfile.dll", IDI_ICON1)
  , "get a handle to the main application icon"
  );

If the ExtractIcon call fails, then the casements::error will have a helpful message, such as "Failed to get a handle to the main application icon. The system cannot find the file specified. (Win32 error2)".

Some API functions have a different return value convention. When using a custom error test, the casements::last_error gives a convienent way to construct the exception object for the latest error. For example:

BOOL get_message_result = GetMessage(&message, 0, 0, 0);
if(-1 == get_message_result)
{
  throw casements::last_error("get the next message");
}

Reading Version Resource Information

The casements::file_version_info class provides easy access to version resource information. This is useful to avoid repeating version strings within the application source code. The application should read its own version resource to format the text of the "about" box.

Modules

A "module" is an executable or dynamic link library. Modules are abstracted by casements::module_type. This class has helper methods to read a module's version resource using the 'version', 'company_name' and 'product_name' member functions. The Win32 module handle can be retrieved using the 'handle' member function. The returned class is convertable to a Win32 HMODULE.

Known Folders

In Windows, standard folder paths are called "known folders". The get_known_folder_path function returns a known folder as a boost::filesystem::path. For example, to get the current user's "Documents" path:

casements::get_known_folder_path(FOLDERID_Documents);

The following functions provide access to specific known folder paths:

Known Folder Name Typical Location Casements function
Program Data Path C:\Program Files... casements::program_data_path()
Roaming Application Data Path C:\Users\username\AppData\Roaming casements::roaming_application_data_path()
Documents Path C:\Users\username\Documents casements::documents_path()
Application Documents Path ...\Documents\ProductName casements::application_documents_path()

Hostname

To get the hostname, use the function casements::hostname().

The following functions provide access to specific known folder paths:

Known Folder Name Typical Location Casements function
Program Data Path C:\Program Files... casements::program_data_path()
Roaming Application Data Path C:\Users\username\AppData\Roaming casements::roaming_application_data_path()
Documents Path C:\Users\username\Documents casements::documents_path()
Application Documents Path ...\Documents\ProductName casements::application_documents_path()

Hostname

To get the hostname, use the function casements::hostname().

License

This library is available under the Boost Software License.

© 2014 Joshua Napoli

Distributed under the Boost Software License, Version 1.0. (See Accompanying File LICENSE_1_0.Txt or copy at http://www.boost.org/LICENSE_1_0.txt)

casements's People

Contributors

joshuanapoli avatar

Watchers

 avatar  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.