/[Sims3RigEditor]/trunk/ViewDDS/NativeMethods.cs
ViewVC logotype

Contents of /trunk/ViewDDS/NativeMethods.cs

Parent Directory Parent Directory | Revision Log Revision Log


Revision 39 - (show annotations) (download)
Thu Aug 5 21:38:32 2010 UTC (9 years, 11 months ago) by william
File size: 8874 byte(s)
update Paint.NET DDS plugin, again...

1 /////////////////////////////////////////////////////////////////////////////////
2 // Paint.NET //
3 // Copyright (C) dotPDN LLC, Rick Brewster, Tom Jackson, and contributors. //
4 // Portions Copyright (C) Microsoft Corporation. All Rights Reserved. //
5 // See src/Resources/Files/License.txt for full licensing and attribution //
6 // details. //
7 // . //
8 /////////////////////////////////////////////////////////////////////////////////
9
10 using System;
11 using System.ComponentModel;
12 using System.Runtime.InteropServices;
13 using System.Text;
14
15 namespace PaintDotNet.SystemLayer
16 {
17 internal static class NativeMethods
18 {
19 internal static bool SUCCEEDED(int hr)
20 {
21 return hr >= 0;
22 }
23
24 [DllImport("shell32.dll", CharSet = CharSet.Unicode, PreserveSig = false)]
25 internal static extern void SHGetFolderPathW(
26 IntPtr hwndOwner,
27 int nFolder,
28 IntPtr hToken,
29 uint dwFlags,
30 StringBuilder lpszPath);
31
32 [DllImport("kernel32.dll", SetLastError = true)]
33 [return: MarshalAs(UnmanagedType.Bool)]
34 public static extern bool DeleteFileW(
35 [MarshalAs(UnmanagedType.LPWStr)] string lpFileName);
36
37 [DllImport("kernel32.dll", SetLastError = true)]
38 [return: MarshalAs(UnmanagedType.Bool)]
39 public static extern bool RemoveDirectoryW(
40 [MarshalAs(UnmanagedType.LPWStr)] string lpPathName);
41
42 [DllImport("user32.dll", SetLastError = true)]
43 public static extern uint WaitForInputIdle(
44 IntPtr hProcess,
45 uint dwMilliseconds);
46
47 [DllImport("user32.dll", SetLastError = true)]
48 [return: MarshalAs(UnmanagedType.Bool)]
49 public static extern bool EnumWindows(
50 [MarshalAs(UnmanagedType.FunctionPtr)] NativeDelegates.EnumWindowsProc lpEnumFunc,
51 IntPtr lParam);
52
53 [DllImport("kernel32.dll", SetLastError = true)]
54 public static extern IntPtr OpenProcess(
55 uint dwDesiredAccess,
56 [MarshalAs(UnmanagedType.Bool)] bool bInheritHandle,
57 uint dwProcessId);
58
59 [DllImport("advapi32.dll", SetLastError = true)]
60 [return: MarshalAs(UnmanagedType.Bool)]
61 public static extern bool OpenProcessToken(
62 IntPtr ProcessHandle,
63 uint DesiredAccess,
64 out IntPtr TokenHandle);
65
66 [DllImport("advapi32.dll", SetLastError = true)]
67 [return: MarshalAs(UnmanagedType.Bool)]
68 public static extern bool DuplicateTokenEx(
69 IntPtr hExistingToken,
70 uint dwDesiredAccess,
71 IntPtr lpTokenAttributes,
72 NativeConstants.SECURITY_IMPERSONATION_LEVEL ImpersonationLevel,
73 NativeConstants.TOKEN_TYPE TokenType,
74 out IntPtr phNewToken);
75
76 [DllImport("advapi32.dll", CharSet = CharSet.Unicode, SetLastError = true)]
77 [return: MarshalAs(UnmanagedType.Bool)]
78 public static extern bool CreateProcessWithTokenW(
79 IntPtr hToken,
80 uint dwLogonFlags,
81 IntPtr lpApplicationName,
82 IntPtr lpCommandLine,
83 uint dwCreationFlags,
84 IntPtr lpEnvironment,
85 IntPtr lpCurrentDirectory,
86 IntPtr lpStartupInfo,
87 out NativeStructs.PROCESS_INFORMATION lpProcessInfo);
88
89 [DllImport("user32.dll", SetLastError = true)]
90 [return: MarshalAs(UnmanagedType.Bool)]
91 public static extern bool OpenClipboard(IntPtr hWndNewOwner);
92
93 [DllImport("user32.dll", SetLastError = true)]
94 [return: MarshalAs(UnmanagedType.Bool)]
95 public static extern bool CloseClipboard();
96
97 [DllImport("user32.dll", SetLastError = true)]
98 public static extern IntPtr GetClipboardData(uint format);
99
100 [DllImport("user32.dll", SetLastError = true)]
101 [return: MarshalAs(UnmanagedType.Bool)]
102 public static extern bool IsClipboardFormatAvailable(uint format);
103
104 [DllImport("shell32.dll", CharSet = CharSet.Unicode, PreserveSig = false)]
105 internal static extern void SHCreateItemFromParsingName(
106 [MarshalAs(UnmanagedType.LPWStr)] string pszPath,
107 IntPtr pbc,
108 ref Guid riid,
109 out IntPtr ppv);
110
111 [DllImport("kernel32.dll", CharSet = CharSet.Unicode, SetLastError = true)]
112 [return: MarshalAs(UnmanagedType.Bool)]
113 internal static extern bool VerifyVersionInfo(
114 ref NativeStructs.OSVERSIONINFOEX lpVersionInfo,
115 uint dwTypeMask,
116 ulong dwlConditionMask);
117
118 [DllImport("kernel32.dll")]
119 internal static extern ulong VerSetConditionMask(
120 ulong dwlConditionMask,
121 uint dwTypeBitMask,
122 byte dwConditionMask);
123
124 [DllImport("kernel32.dll", SetLastError = true)]
125 [return: MarshalAs(UnmanagedType.Bool)]
126 internal static extern bool DeviceIoControl(
127 IntPtr hDevice,
128 uint dwIoControlCode,
129 IntPtr lpInBuffer,
130 uint nInBufferSize,
131 IntPtr lpOutBuffer,
132 uint nOutBufferSize,
133 ref uint lpBytesReturned,
134 IntPtr lpOverlapped);
135
136 [DllImport("shell32.dll", CharSet = CharSet.Unicode, SetLastError = true)]
137 [return: MarshalAs(UnmanagedType.Bool)]
138 internal static extern bool ShellExecuteExW(ref NativeStructs.SHELLEXECUTEINFO lpExecInfo);
139
140 [DllImport("kernel32.dll", SetLastError = true)]
141 [return: MarshalAs(UnmanagedType.Bool)]
142 internal static extern bool GlobalMemoryStatusEx(ref NativeStructs.MEMORYSTATUSEX lpBuffer);
143
144 [DllImport("shell32.dll", SetLastError = false)]
145 internal static extern void SHAddToRecentDocs(uint uFlags, IntPtr pv);
146
147 [DllImport("kernel32.dll", SetLastError = false)]
148 internal static extern void GetSystemInfo(ref NativeStructs.SYSTEM_INFO lpSystemInfo);
149
150 [DllImport("kernel32.dll", SetLastError = false)]
151 internal static extern void GetNativeSystemInfo(ref NativeStructs.SYSTEM_INFO lpSystemInfo);
152
153 [DllImport("Wintrust.dll", PreserveSig = true, SetLastError = false)]
154 internal extern static unsafe int WinVerifyTrust(
155 IntPtr hWnd,
156 ref Guid pgActionID,
157 ref NativeStructs.WINTRUST_DATA pWinTrustData
158 );
159
160 [DllImport("SetupApi.dll", CharSet = CharSet.Unicode, SetLastError = true)]
161 internal static extern IntPtr SetupDiGetClassDevsW(
162 ref Guid ClassGuid,
163 [MarshalAs(UnmanagedType.LPWStr)] string Enumerator,
164 IntPtr hwndParent,
165 uint Flags);
166
167 [DllImport("SetupApi.dll", CharSet = CharSet.Unicode, SetLastError = true)]
168 [return: MarshalAs(UnmanagedType.Bool)]
169 internal static extern bool SetupDiDestroyDeviceInfoList(IntPtr DeviceInfoSet);
170
171 [DllImport("SetupApi.dll", CharSet = CharSet.Unicode, SetLastError = true)]
172 [return: MarshalAs(UnmanagedType.Bool)]
173 internal static extern bool SetupDiEnumDeviceInfo(
174 IntPtr DeviceInfoSet,
175 uint MemberIndex,
176 ref NativeStructs.SP_DEVINFO_DATA DeviceInfoData);
177
178 [DllImport("SetupApi.dll", CharSet = CharSet.Unicode, SetLastError = true)]
179 [return: MarshalAs(UnmanagedType.Bool)]
180 internal static extern bool SetupDiGetDeviceInstanceIdW(
181 IntPtr DeviceInfoSet,
182 ref NativeStructs.SP_DEVINFO_DATA DeviceInfoData,
183 IntPtr DeviceInstanceId,
184 uint DeviceInstanceIdSize,
185 out uint RequiredSize);
186
187 internal static void ThrowOnWin32Error(string message)
188 {
189 int lastWin32Error = Marshal.GetLastWin32Error();
190 ThrowOnWin32Error(message, lastWin32Error);
191 }
192
193 internal static void ThrowOnWin32Error(string message, NativeErrors lastWin32Error)
194 {
195 ThrowOnWin32Error(message, (int)lastWin32Error);
196 }
197
198 internal static void ThrowOnWin32Error(string message, int lastWin32Error)
199 {
200 if (lastWin32Error != NativeConstants.ERROR_SUCCESS)
201 {
202 string exMessageFormat = "{0} ({1}, {2})";
203 string exMessage = string.Format(exMessageFormat, message, lastWin32Error, ((NativeErrors)lastWin32Error).ToString());
204
205 throw new Win32Exception(lastWin32Error, exMessage);
206 }
207 }
208 }
209 }

  ViewVC Help
Powered by ViewVC 1.1.22