• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 using System;
6 using System.Collections.Generic;
7 using System.Runtime.InteropServices;
8 using System.Text;
9 
10 namespace StatsViewer {
11   /// <summary>
12   /// Win32 API constants, structs, and wrappers for access via C#.
13   /// </summary>
14   class Win32 {
15     #region Constants
16     public enum MapAccess {
17       FILE_MAP_COPY = 0x0001,
18       FILE_MAP_WRITE = 0x0002,
19       FILE_MAP_READ = 0x0004,
20       FILE_MAP_ALL_ACCESS = 0x001f,
21     }
22 
23     public const int GENERIC_READ = unchecked((int)0x80000000);
24     public const int GENERIC_WRITE = unchecked((int)0x40000000);
25     public const int OPEN_ALWAYS = 4;
26     public static readonly IntPtr INVALID_HANDLE_VALUE = new IntPtr(-1);
27     #endregion
28 
29     [DllImport("kernel32", SetLastError=true, CharSet=CharSet.Auto)]
CreateFile( String lpFileName, int dwDesiredAccess, int dwShareMode, IntPtr lpSecurityAttributes, int dwCreationDisposition, int dwFlagsAndAttributes, IntPtr hTemplateFile)30     public static extern IntPtr CreateFile (
31        String lpFileName, int dwDesiredAccess, int dwShareMode,
32        IntPtr lpSecurityAttributes, int dwCreationDisposition,
33        int dwFlagsAndAttributes, IntPtr hTemplateFile);
34 
35     [DllImport("kernel32", SetLastError=true)]
MapViewOfFile( IntPtr hFileMappingObject, int dwDesiredAccess, int dwFileOffsetHigh, int dwFileOffsetLow, int dwNumBytesToMap)36     public static extern IntPtr MapViewOfFile (
37        IntPtr hFileMappingObject, int dwDesiredAccess, int dwFileOffsetHigh,
38        int dwFileOffsetLow, int dwNumBytesToMap);
39 
40     [DllImport("kernel32", SetLastError=true, CharSet=CharSet.Auto)]
OpenFileMapping( int dwDesiredAccess, bool bInheritHandle, String lpName)41     public static extern IntPtr OpenFileMapping (
42        int dwDesiredAccess, bool bInheritHandle, String lpName);
43 
44     [DllImport("kernel32", SetLastError=true)]
UnmapViewOfFile(IntPtr lpBaseAddress)45     public static extern bool UnmapViewOfFile (IntPtr lpBaseAddress);
46 
47     [DllImport("kernel32", SetLastError = true)]
CloseHandle(IntPtr handle)48     public static extern bool CloseHandle(IntPtr handle);
49   }
50 }
51