https://github.com/siddiqsoft/acw32h
Auto Close Win32 Handles such as HANDLE and HINTERNET. Use nuget package https://www.nuget.org/packages/SiddiqSoft.acw32h/
https://github.com/siddiqsoft/acw32h
handle hinternet win32
Last synced: 3 months ago
JSON representation
Auto Close Win32 Handles such as HANDLE and HINTERNET. Use nuget package https://www.nuget.org/packages/SiddiqSoft.acw32h/
- Host: GitHub
- URL: https://github.com/siddiqsoft/acw32h
- Owner: SiddiqSoft
- License: bsd-3-clause
- Created: 2021-07-07T00:19:32.000Z (almost 5 years ago)
- Default Branch: main
- Last Pushed: 2024-12-07T09:22:36.000Z (over 1 year ago)
- Last Synced: 2025-11-27T12:48:04.268Z (7 months ago)
- Topics: handle, hinternet, win32
- Language: C++
- Homepage:
- Size: 86.9 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
Auto Closing/Releasing Win32 Handle Objects
-------------------------------------------
[](https://github.com/SiddiqSoft/acw32handle/actions/workflows/codeql-analysis.yml)
[](https://dev.azure.com/siddiqsoft/siddiqsoft/_build/latest?definitionId=4&branchName=main)




# Objective
Make it easy to track the Win32 `HANDLE` and `HINTERNET` objects while keeping their use as drop-in replacement for their respective `HANDLE` or `HINTERNET` objects.
Use only when you're holding objects that your application is required to close/release.
# Requirements
- C++17
- Useful for Windows projects
# Usage
- Use the nuget [SiddiqSoft.acw32h](https://www.nuget.org/packages/SiddiqSoft.acw32h/)
- Be sure to use the proper class `ACW32HANDLE` or `ACW32HINTERNET`. The underlying types of `HANDLE` and `HINTERNET` end up the same so it is not possible to template them into a single class.
- Make sure to include the relevant file for your case: `acw32handle.hpp` or `acw32hinternet.hpp` as windows headers occasionally have peculiar ordering (notably when WinHTTP, WinINET, WinSock are in the mix).
Example (when using nuget to add the header in the solution)
```cpp
#include
#include "siddiqsoft/acw32handle.hpp"
#include
#include "siddiqsoft/acw32hinternet.hpp"
void foo()
{
// Use the object
siddiqsoft::ACW32HANDLE h( ::CreateFileA(...) );
// or
HANDLE mh = ::CreateFile(.....);
// A std::move is required since the implementation requires
// the transfer of ownership in order to close the handle.
ACW32HANDLE myHandle( std::move(mh) );
// C++ will cleanup the handle if it was properly allocated!
}
```
© 2021 Siddiq Software LLC. All rights reserved. Refer to [LICENSE](LICENSE).