source: branches/eraser6/CodeReview/Eraser.Util.Native/Eraser.Util.Native.h @ 1535

Revision 1535, 2.5 KB checked in by lowjoel, 5 years ago (diff)

Blind Eraser.Util.Unlocker = >Eraser.Util.Native

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
Line 
1/*
2 * $Id$
3 * Copyright 2008-2009 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 "Unlocker.h"
25
26using namespace System;
27using namespace System::Collections::Generic;
28using namespace System::Collections::ObjectModel;
29using namespace Microsoft::Win32::SafeHandles;
30
31namespace Eraser {
32namespace Util {
33    /// Represents one open handle in the system.
34    public ref struct OpenHandle
35    {
36    internal:
37        /// Constructor.
38        ///
39        /// \param[in] handle The handle to wrap.
40        /// \param[in] pid The Process ID of the handle.
41        /// \param[in] path The path to the file.
42        OpenHandle(IntPtr handle, int pid, String^ path)
43        {
44            this->handle = handle;
45            this->processId = pid;
46            this->path = path;
47        }
48
49    public:
50        /// Retrieves all open handles on the system
51        static property ReadOnlyCollection<OpenHandle^>^ Items
52        {
53            ReadOnlyCollection<OpenHandle^>^ get();
54        }
55
56        /// Force the handle to close.
57        bool Close();
58
59        /// The handle to the file, in the context of the owning process.
60        property IntPtr Handle
61        {
62            IntPtr get()
63            {
64                return handle;
65            }
66        }
67
68        /// The path to the file.
69        property String^ Path
70        {
71            String^ get()
72            {
73                return path;
74            }
75
76            void set(String^ value)
77            {
78                path = value;
79            }
80        }
81
82        /// The process ID of the process owning the handle.
83        property int ProcessId
84        {
85            int get()
86            {
87                return processId;
88            }
89
90            void set(int value)
91            {
92                processId = value;
93            }
94        };
95
96    private:
97        /// Resolves a handle to a file name.
98        ///
99        /// \param[in] handle The file handle to resolve.
100        /// \param[in] pid The process ID of the owning process.
101        /// \return A string containing the path to the file, or null.
102        static String^ ResolveHandlePath(IntPtr handle, int pid);
103
104    private:
105        static HANDLE* NameResolutionThread;
106        static NameResolutionThreadParams* NameResolutionThreadParam;
107
108        IntPtr handle;
109        String^ path;
110        int processId;
111    };
112}
113}
Note: See TracBrowser for help on using the repository browser.