source: branches/eraser6/6.0/Installer/Bootstrapper/Handle.h @ 1445

Revision 1445, 1.6 KB checked in by lowjoel, 4 years ago (diff)

-Ensure that the bootstrapper checks the service pack level for the installed .NET framework; currently we check for .NET 3.5 SP1.
-Minor code cleanup (factored out the Handle class to be a template, allowing any abstract handle to be used)

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
Line 
1/*
2 * $Id$
3 * Copyright 2008-2010 The Eraser Project
4 * Original Author: Joel Low <lowjoel@users.sourceforge.net>
5 * Modified By:
6 *
7 * This file is part of Eraser.
8 *
9 * Eraser is free software: you can redistribute it and/or modify it under the
10 * terms of the GNU General Public License as published by the Free Software
11 * Foundation, either version 3 of the License, or (at your option) any later
12 * version.
13 *
14 * Eraser is distributed in the hope that it will be useful, but WITHOUT ANY
15 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
16 * A PARTICULAR PURPOSE. See the GNU General Public License for more details.
17 *
18 * A copy of the GNU General Public License can be found at
19 * <http://www.gnu.org/licenses/>.
20 */
21
22#pragma once
23
24#include <windows.h>
25
26/// Manages the lifetime of a Windows handle. This class will destroy the handle
27/// based on its type upon destruction of this object.
28template<typename handleType> class Handle
29{
30public:
31    /// Constructor.
32    ///
33    /// \param[in] handle The handle to manage.
34    Handle(handleType handle = NULL)
35    {
36        thisHandle = handle;
37    }
38
39    ~Handle();
40
41    /// Converts the handle back to an unmanaged handle.
42    operator handleType()
43    {
44        return thisHandle;
45    }
46
47    /// Returns a mutable reference to the internal value. This allows this object
48    /// to be used when a function takes a pointer to a handle (e.g. for Out parameters)
49    operator handleType*()
50    {
51        return &thisHandle;
52    }
53
54private:
55    /// The handle this object is managing.
56    handleType thisHandle;
57};
58
59Handle<HANDLE>::~Handle()
60{
61    CloseHandle(thisHandle);
62}
63
64Handle<HKEY>::~Handle()
65{
66    RegCloseKey(thisHandle);
67}
Note: See TracBrowser for help on using the repository browser.