forked from ClearFoundry/ClearScript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNativeMethods.cs
More file actions
107 lines (92 loc) · 3.23 KB
/
NativeMethods.cs
File metadata and controls
107 lines (92 loc) · 3.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.
using System;
using System.Runtime.InteropServices;
namespace Microsoft.ClearScript.Util
{
[StructLayout(LayoutKind.Sequential)]
internal struct SystemInfo
{
public ushort ProcessorArchitecture;
public ushort Reserved;
public uint PageSize;
public IntPtr MinimumApplicationAddress;
public IntPtr MaximumApplicationAddress;
public IntPtr ActiveProcessorMask;
public uint NumberOfProcessors;
public uint ProcessorType;
public uint AllocationGranularity;
public ushort ProcessorLevel;
public ushort ProcessorRevision;
}
internal static class NativeMethods
{
[DllImport("kernel32", ExactSpelling = true, SetLastError = true)]
public static extern IntPtr LoadLibraryW(
[In] [MarshalAs(UnmanagedType.LPWStr)] string path
);
[DllImport("kernel32.dll", SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool FreeLibrary(
[In] IntPtr hLibrary
);
[DllImport("ole32.dll", ExactSpelling = true)]
public static extern uint CLSIDFromProgID(
[In] [MarshalAs(UnmanagedType.LPWStr)] string progID,
[Out] out Guid clsid
);
[DllImport("ole32.dll", ExactSpelling = true)]
public static extern uint CoCreateInstance(
[In] ref Guid clsid,
[In] IntPtr pOuter,
[In] uint clsContext,
[In] ref Guid iid,
[Out] out IntPtr pInterface
);
[DllImport("oleaut32.dll", ExactSpelling = true)]
public static extern void VariantInit(
[In] IntPtr pVariant
);
[DllImport("oleaut32.dll", ExactSpelling = true)]
public static extern uint VariantClear(
[In] IntPtr pVariant
);
[DllImport("kernel32.dll", SetLastError = true)]
public static extern IntPtr HeapCreate(
[In] uint options,
[In] UIntPtr initialSize,
[In] UIntPtr maximumSize
);
[DllImport("kernel32.dll", SetLastError = false)]
public static extern IntPtr HeapAlloc(
[In] IntPtr hHeap,
[In] uint flags,
[In] UIntPtr size
);
[DllImport("kernel32.dll", SetLastError = true)]
public static extern bool HeapFree(
[In] IntPtr hHeap,
[In] uint flags,
[In] IntPtr pBlock
);
[DllImport("kernel32.dll", SetLastError = true)]
public static extern bool HeapDestroy(
[In] IntPtr hHeap
);
[DllImport("kernel32.dll", SetLastError = true)]
public static extern bool VirtualProtect(
[In] IntPtr pBlock,
[In] UIntPtr size,
[In] uint newProtect,
[Out] out uint oldProtect
);
[DllImport("kernel32.dll", SetLastError = false)]
public static extern void GetSystemInfo(
[Out] out SystemInfo info
);
[DllImport("kernel32.dll")]
public static extern void GetNativeSystemInfo(
[Out] out SystemInfo info
);
}
}