• Cnic.SafeNativeMethods


      1 using System;
      2 using System.Collections.Generic;
      3 using System.Text;
      4 using System.Runtime.InteropServices;
      5 using System.ComponentModel;
      6 //using System.Drawing;
      7 
      8 namespace Cnic
      9 {
     10     public class SafeNativeMethods
     11     {
     12         public const int INVALID_HANDLE_VALUE = -1;
     13         public const int NULL = 0;
     14         public const int ERROR_SUCCESS = 0;
     15         public const int FILE_READ_DATA = 0x0001;
     16         public const int FILE_SHARE_READ = 0x00000001;
     17         public const int OPEN_EXISTING = 3;
     18         public const int GENERIC_READ = unchecked((int)0x80000000);
     19         public const int GENERIC_WRITE = unchecked((int)0x40000000);
     20         public const int METHOD_BUFFERED = 0;
     21         public const int METHOD_OUT_DIRECT = 2;
     22         public const int METHOD_NEITHER = 3;
     23         public const int FILE_ANY_ACCESS = 0;
     24         public const int FILE_DEVICE_VIRTUAL_DISK = 0x00000024;
     25         public const long FILE_DEVICE_PHYSICAL_NETCARD = 0x00000017;
     26 
     27         public const int SC_MONITORPOWER = 0xF170;
     28 
     29         public const int SE_PRIVILEGE_ENABLED = 0x00000002;
     30         public const int TOKEN_QUERY = 0x00000008;
     31         public const int TOKEN_ADJUST_PRIVILEGES = 0x00000020;
     32         public const string SE_SHUTDOWN_NAME = "SeShutdownPrivilege";
     33         public const int EWX_LOGOFF = 0x00000000;
     34         public const int EWX_SHUTDOWN = 0x00000001;
     35         public const int EWX_REBOOT = 0x00000002;
     36         public const int EWX_FORCE = 0x00000004;
     37         public const int EWX_POWEROFF = 0x00000008;
     38         public const int EWX_FORCEIFHUNG = 0x00000010;
     39 
     40         public delegate IntPtr HookProc(int code, IntPtr wparam, IntPtr lparam);
     41         public const int ULW_COLORKEY = 0x00000001;
     42         public const int ULW_ALPHA = 0x00000002;
     43         public const int ULW_OPAQUE = 0x00000004;
     44         public const uint LWA_COLORKEY = 0x00000001;
     45         public const uint LWA_ALPHA = 0x00000002;
     46 
     47         public const int HC_ACTION = 0x00000000;
     48         public const int HC_GETNEXT = 0x00000001;
     49         public const int HC_SKIP = 0x00000002;
     50         public const int HC_NOREMOVE = 0x00000003;
     51         public const int HC_NOREM = 0x00000003;
     52         public const int HC_SYSMODALON = 0x00000004;
     53         public const int HC_SYSMODALOFF = 0x00000005;
     54 
     55         public const int MOUSE = 0;
     56         public const int KEYBOARD = 1;
     57         public const int HARDWARE = 2;
     58         public const short VK_LWIN = 0x5B;
     59         public const short KEYEVENTF_KEYUP = 0x0002;
     60         public const int WM_SYSCOMMAND = 0x112;
     61         public const int HTCAPTION = 0x2;
     62         public const int WS_SHOWNORMAL = 1;
     63         public const byte AC_SRC_OVER = 0x00;
     64         public const byte AC_SRC_ALPHA = 0x01;
     65         public const int SRCCOPY = 0x40CC0020;
     66         public const Int16 IMAGE_ICON = 1;
     67         public const int LOAD_LIBRARY_AS_DATAFILE = 0x2;
     68         public const int RT_ICON = 3;
     69         public const int RT_GROUP_ICON = 14;
     70         public const int WM_KEYDOWN = 0x100;
     71         public const int WM_KEYUP = 0x101;
     72         public const int MOUSEEVENTF_MOVE = 0x0001;
     73         public const int MOUSEEVENTF_LEFTDOWN = 0x0002;
     74         public const int MOUSEEVENTF_LEFTUP = 0x0004;
     75         public const int MOUSEEVENTF_RIGHTDOWN = 0x0008;
     76         public const int MOUSEEVENTF_RIGHTUP = 0x0010;
     77         public const int MOUSEEVENTF_MIDDLEDOWN = 0x0020;
     78         public const int MOUSEEVENTF_MIDDLEUP = 0x0040;
     79         public const int MOUSEEVENTF_ABSOLUTE = 0x8000;
     80         public const int SC_SIZE = 0xF000;
     81         public const int SC_MOVE = 0xF010;
     82         public const int SC_MINIMIZE = 0xF020;
     83         public const int SC_MAXIMIZE = 0xF030;
     84         public const int SC_NEXTWINDOW = 0xF040;
     85         public const int SC_PREVWINDOW = 0xF050;
     86         public const int SC_CLOSE = 0xF060;
     87         public const int SC_VSCROLL = 0xF070;
     88         public const int SC_HSCROLL = 0xF080;
     89         public const int SC_MOUSEMENU = 0xF090;
     90         public const int SC_KEYMENU = 0xF100;
     91         public const int SC_ARRANGE = 0xF110;
     92         public const int SC_RESTORE = 0xF120;
     93         public const int AW_HOR_POSITIVE = 0x00000001;
     94         public const int AW_HOR_NEGATIVE = 0x00000002;
     95         public const int AW_VER_POSITIVE = 0x00000004;
     96         public const int AW_VER_NEGATIVE = 0x00000008;
     97         public const int AW_CENTER = 0x00000010;
     98         public const int AW_HIDE = 0x00010000;
     99         public const int AW_ACTIVATE = 0x00020000;
    100         public const int AW_SLIDE = 0x00040000;
    101         public const int AW_BLEND = 0x00080000;
    102 
    103 
    104         public const uint WS_EX_LAYERED = 0x80000;
    105         public const int WS_EX_TRANSPARENT = 0x20;
    106         public const int GWL_STYLE = (-16);
    107         public const int GWL_EXSTYLE = (-20);
    108 
    109 
    110 
    111         [StructLayout(LayoutKind.Sequential, Pack = 1)]
    112         struct ARGB
    113         {
    114             public byte Blue;
    115             public byte Green;
    116             public byte Red;
    117             public byte Alpha;
    118         }
    119 
    120 
    121         [StructLayout(LayoutKind.Sequential, Pack = 1)]
    122         public struct BLENDFUNCTION
    123         {
    124             public byte BlendOp;
    125             public byte BlendFlags;
    126             public byte SourceConstantAlpha;
    127             public byte AlphaFormat;
    128         }
    129         //Security Attributes
    130         public struct SECURITY_ATTRIBUTES
    131         {
    132             public int nLength;
    133             public IntPtr lpSecurityDescriptor;
    134             public int bInheritHandle;
    135         }
    136 
    137 
    138 
    139         /// <summary>
    140         /// 枚举,钩子的类型 WindowsMessageHook
    141         /// </summary>
    142         public enum HookType
    143         {
    144 
    145             MsgFilter = -1,
    146 
    147             JournalRecord = 0,
    148             JournalPlayback = 1,
    149             Keyboard = 2,
    150             GetMessage = 3,
    151             CallWndProc = 4,
    152             CBT = 5,
    153             SysMsgFilter = 6,
    154             Mouse = 7,
    155             Hardware = 8,
    156             Debug = 9,
    157             Shell = 10,
    158             ForegroundIdle = 11,
    159             CallWndProcRet = 12,
    160             KeyboardLL = 13,
    161             MouseLL = 14
    162         }
    163         [StructLayout(LayoutKind.Sequential, Pack = 1)]
    164         public struct TOKEN_PRIVILEGES
    165         {
    166             public int PrivilegeCount;
    167             public long Luid;
    168             public int Attributes;
    169         }
    170 
    171         [StructLayout(LayoutKind.Sequential)]
    172         public struct HARDWAREINPUT
    173         {
    174             public int uMsg;
    175             public short wParamL;
    176             public short wParamH;
    177         }
    178 
    179         [StructLayout(LayoutKind.Explicit)]
    180         public struct Input
    181         {
    182             [FieldOffset(0)]
    183             public int type;
    184             [FieldOffset(4)]
    185             public MOUSEINPUT mi;
    186             [FieldOffset(4)]
    187             public KEYBDINPUT ki;
    188             [FieldOffset(4)]
    189             public HARDWAREINPUT hi;
    190         }
    191 
    192 
    193         [StructLayout(LayoutKind.Sequential)]
    194         public struct KeyboardHookStruct
    195         {
    196             public int vkCode; //表示一个在1到254间的虚似键盘码
    197             public int scanCode; //表示硬件扫描码
    198             public int flags;
    199             public int time;
    200             public int dwExtraInfo;
    201         }
    202         public enum KeyModifiers
    203         {
    204             None = 0,
    205             Alt = 1,
    206             Control = 2,
    207             Shift = 4,
    208             Windows = 8
    209         }
    210         [StructLayout(LayoutKind.Sequential)]
    211         public struct KEYBDINPUT
    212         {
    213             public short wVk;
    214             public short wScan;
    215             public int dwFlags;
    216             public int time;
    217             public IntPtr dwExtraInfo;
    218         }
    219         [StructLayout(LayoutKind.Sequential)]
    220         public struct MOUSEINPUT
    221         {
    222             public int dx;
    223             public int dy;
    224             public int mouseData;
    225             public int dwFlags;
    226             public int time;
    227             public IntPtr dwExtraInfo;
    228         }
    229         //[StructLayout(LayoutKind.Sequential)]
    230         //public struct Point
    231         //{
    232         //    public Int32 x;
    233         //    public Int32 y;
    234 
    235         //    public Point(Int32 x, Int32 y) { this.x = x; this.y = y; }
    236         //}
    237 
    238         public struct POINTAPI
    239         {
    240             public int x;
    241             public int y;
    242         }
    243 
    244         public struct RECT
    245         {
    246             public int left;
    247             public int top;
    248             public int right;
    249             public int bottom;
    250         }
    251 
    252         //[StructLayout(LayoutKind.Sequential)]
    253         //public struct Size
    254         //{
    255         //    public Int32 cx;
    256         //    public Int32 cy;
    257 
    258         //    public Size(Int32 cx, Int32 cy) { this.cx = cx; this.cy = cy; }
    259         //}
    260 
    261         /// <summary>
    262         /// 该函数对指定的源设备环境区域中的像素进行位块(bit_block)转换,以传送到目标设备环境。
    263         /// </summary>
    264         /// <param name="TarPtr">目标设备环境的句柄。</param>
    265         /// <param name="DestX">指定目标矩形区域左上角的X轴逻辑坐标。</param>
    266         /// <param name="DestY">指定目标矩形区域左上角的Y轴逻辑坐标。</param>
    267         /// <param name="Width">指定源和目标矩形区域的逻辑宽度。</param>
    268         /// <param name="Height">指定源和目标矩形区域的逻辑高度。</param>
    269         /// <param name="DcPtr">指向源设备环境的句柄。</param>
    270         /// <param name="ScrX">指定源矩形区域左上角的X轴逻辑坐标。</param>
    271         /// <param name="ScrY">指定源矩形区域左上角的Y轴逻辑坐标。</param>
    272         /// <param name="dwRop">指定光栅操作代码。这些代码将定义源矩形区域的颜色数据,如何与目标矩形区域的颜色数据组合以完成最后的颜色。:BLACKNESS,DSTINVERT,MERGECOPY,MERGEPAINT,NOTSRCCOPY,NOTSRCERASE,PATCOPY,PATPAINT,PATINVERT,SRCAND,SRCCOPY,SRCERASE,SRCINVERT,SRCPAINT,WHITENESS</param>
    273         /// <returns>如果函数成功,那么返回值非零;如果函数失败,则返回值为零。</returns>
    274         [DllImport("gdi32.dll", SetLastError = true)]
    275         public static extern bool BitBlt(IntPtr TarPtr, int DestX, int DestY, int Width, int Height, IntPtr DcPtr, int ScrX, int ScrY, int dwRop);
    276 
    277         /// <summary>
    278         /// 调用下一个钩子
    279         /// </summary>
    280         /// <param name="handle">当前钩子的句柄</param>
    281         /// <param name="code">钩子代码  HC_ACTION = 0,HC_GETNEXT = 1,HC_SKIP = 2,HC_NOREMOVE = 3,HC_NOREM = HC_NOREMOVE;,HC_SYSMODALON = 4,HC_SYSMODALOFF = 5;</param>
    282         /// <param name="wparam">要传递的参数</param>
    283         /// <param name="lparam">要传递的参数</param>
    284         /// <returns></returns>
    285         [DllImport("user32.dll", SetLastError = true)]
    286         public static extern IntPtr CallNextHookEx(IntPtr handle, int code, IntPtr wparam, IntPtr lparam);
    287 
    288         [DllImport("gdi32.dll", SetLastError = true)]
    289         public static extern IntPtr CreateCompatibleBitmap(IntPtr hDC, int nWidth, int nHeight);
    290 
    291         [DllImport("gdi32.dll", SetLastError = true)]
    292         public static extern IntPtr CreateCompatibleDC(IntPtr hDC);
    293 
    294 
    295         [DllImport("gdi32.dll", SetLastError = true)]
    296         public static extern IntPtr CreateDC(string lpszDriver, string lpszDevice, string lpszOutput, IntPtr lpInitData);
    297 
    298 
    299         [DllImport("gdi32.dll", SetLastError = true)]
    300         public static extern bool DeleteDC(IntPtr hDC);
    301 
    302         [DllImport("gdi32.dll", SetLastError = true)]
    303         public static extern bool DeleteObject(IntPtr hObject);
    304 
    305         [DllImport("user32.dll", SetLastError = true)]
    306         public static extern bool DrawIcon(IntPtr hdc, int x, int y, IntPtr hIcon);
    307 
    308         public delegate int EnumResNamesProc(IntPtr hMod, IntPtr lpszType, IntPtr lpszName, IntPtr lParam);
    309 
    310         [DllImport("kernel32.dll", CharSet = CharSet.Auto)]
    311         public static extern int EnumResourceNames(IntPtr hModule, IntPtr lpType, [MarshalAs(UnmanagedType.FunctionPtr)] EnumResNamesProc lpEnumFunc, IntPtr lParam);
    312 
    313         [DllImport("kernel32.dll", SetLastError = true)]
    314         public static extern int FreeLibrary(IntPtr hLibModule);
    315 
    316         [DllImport("kernel32", CharSet = CharSet.Auto)]
    317         public static extern IntPtr FindResource(IntPtr hInstance, [MarshalAs(UnmanagedType.LPTStr)] string lpName, IntPtr lpType);
    318 
    319         [DllImport("kernel32.dll", SetLastError = true)]
    320         public static extern int FreeResource(IntPtr hResData);
    321 
    322         [DllImport("user32.dll", CharSet = CharSet.Auto, ExactSpelling = true)]
    323         public static extern IntPtr GetCursor();
    324 
    325 
    326         [DllImport("User32.dll", EntryPoint = "GetKeyState", CharSet = CharSet.Auto)]
    327         public static extern short GetKeyState(int nVirtKey);
    328 
    329         [DllImport("user32.dll", SetLastError = true)]
    330         public static extern IntPtr GetDC(IntPtr hwnd);
    331 
    332         [DllImport("user32.dll", SetLastError = true)]
    333         public static extern IntPtr GetDesktopWindow();
    334 
    335         [DllImport("user32.dll", EntryPoint = "GetSystemMetrics")]
    336         public static extern int GetSystemMetrics(int nIndex);
    337 
    338         [DllImport("user32.dll", SetLastError = true)]
    339         public static extern IntPtr GetWindowDC(IntPtr hwnd);
    340 
    341         [DllImport("kernel32", CharSet = CharSet.Auto)]
    342         public static extern IntPtr LoadLibraryEx([MarshalAs(UnmanagedType.LPTStr)] string lpLibFileName, IntPtr hFile, int dwFlags);
    343 
    344         [DllImport("kernel32.dll", SetLastError = true)]
    345         public static extern IntPtr LoadResource(IntPtr hInstance, IntPtr hResInfo);
    346 
    347         [DllImport("kernel32.dll", SetLastError = true)]
    348         public static extern IntPtr LockResource(IntPtr hResData);
    349 
    350         [DllImport("user32.dll", SetLastError = true)]
    351         public static extern int mouse_event(int dwFlags, int dx, int dy, int cButtons, int dwExtraInfo);
    352 
    353         /// <summary>
    354         /// 
    355         /// </summary>
    356         /// <param name="hwnd">Window to copy,Handle to the window that will be copied. </param>
    357         /// <param name="hdcBlt">HDC to print into,Handle to the device context. </param>
    358         /// <param name="nFlags">Optional flags,Specifies the drawing options. It can be one of the following values. </param>
    359         /// <returns></returns>
    360         [DllImport("user32.dll", SetLastError = true)]
    361         public static extern bool PrintWindow(IntPtr hwnd, IntPtr hdcBlt, UInt32 nFlags);
    362 
    363         [DllImport("user32.dll", SetLastError = true)]
    364         public static extern bool RegisterHotKey(IntPtr hWnd, int id, uint fsModifiers, System.Windows.Forms.Keys vk);
    365 
    366         [DllImport("user32.dll", SetLastError = true)]
    367         public static extern Int32 ReleaseDC(IntPtr hwnd, IntPtr hdc);
    368 
    369         [DllImport("gdi32.dll", SetLastError = true)]
    370         public static extern IntPtr SelectObject(IntPtr hDC, IntPtr hObject);
    371 
    372         [DllImport("user32.dll", EntryPoint = "SetCursorPos")]
    373         public static extern int SetCursorPos(int x, int y);
    374 
    375         [DllImport("kernel32.dll", SetLastError = true)]
    376         public static extern int SizeofResource(IntPtr hInstance, IntPtr hResInfo);
    377 
    378         [DllImport("gdi32.dll", SetLastError = true)]
    379         public static extern bool StretchBlt(IntPtr hObjec, int nXDest, int nYDest, int nWidth, int nHeight, IntPtr hObjectSource, int nXSrc, int nYSrc, int nSrcWidth, int nSrcHeight, uint dwRop);
    380 
    381 
    382         [DllImport("user32.dll", SetLastError = true)]
    383         public static extern bool UnregisterHotKey(IntPtr hWnd, int id);
    384 
    385         [DllImport("User32.dll", EntryPoint = "SystemParametersInfo")]
    386         public static extern int SystemParametersInfo(int UAction, int UParam, string IpvParam, int fuWinIni);
    387 
    388         [DllImport("kernel32.dll", SetLastError = true)]
    389         public static extern bool SetProcessWorkingSetSize(IntPtr handle, int minimumWorkingSetSize, int maximumWorkingSetSize);
    390 
    391         [DllImport("user32.dll", SetLastError = true)]
    392         public static extern IntPtr SetWindowsHookEx(int idHook, [MarshalAs(UnmanagedType.FunctionPtr)] HookProc lpfn, IntPtr hinstance, int threadID);
    393 
    394 
    395         [DllImport("user32.dll", SetLastError = true)]
    396         public static extern void UnhookWindowsHookEx(IntPtr handle);
    397 
    398         [DllImport("user32.dll", ExactSpelling = true, SetLastError = true)]
    399         public static extern bool UpdateLayeredWindow(IntPtr hwnd, IntPtr hdcDst, ref System.Drawing.Point pptDst, ref System.Drawing.Size psize, IntPtr hdcSrc, ref System.Drawing.Point pprSrc, Int32 crKey, ref BLENDFUNCTION pblend, Int32 dwFlags);
    400 
    401         [DllImport("user32.dll", EntryPoint = "SwapMouseButton")]
    402         public static extern int SwapMouseButton(int bSwap);
    403 
    404         [DllImport("user32", EntryPoint = "ClipCursor")]
    405         public static extern int ClipCursor(ref RECT lpRect);
    406 
    407         [DllImport("user32.dll", EntryPoint = "GetCursorPos")]
    408         public static extern int GetCursorPos(ref System.Drawing.Point lpPoint);
    409 
    410         [DllImport("user32.dll", EntryPoint = "ShowCursor")]
    411         public static extern bool ShowCursor(bool bShow);
    412 
    413         [DllImport("user32.dll", EntryPoint = "EnableWindow")]
    414         public static extern int EnableWindow(int hwnd, int fEnable);
    415 
    416         [DllImport("user32.dll", EntryPoint = "GetWindowRect")]
    417         public static extern int GetWindowRect(int hwnd, ref RECT lpRect);
    418 
    419 
    420         [DllImport("user32.dll", EntryPoint = "SetDoubleClickTime")]
    421         public static extern int SetDoubleClickTime(int wCount);
    422 
    423         [DllImport("user32.dll", EntryPoint = "GetDoubleClickTime")]
    424         public static extern int GetDoubleClickTime();
    425 
    426         [DllImport("kernel32.DLL", EntryPoint = "Sleep")]
    427         public static extern void Sleep(int dwMilliseconds);
    428 
    429         [DllImport("user32.dll", SetLastError = true)]
    430         public static extern bool ShowWindowsAsync(IntPtr hWnd, int cmdShow);
    431 
    432         [DllImport("user32.dll", SetLastError = true)]
    433         public static extern bool SetForegroundWindows(IntPtr hWnd);
    434 
    435         [DllImport("User32.dll", EntryPoint = "SendInput", CharSet = CharSet.Auto, SetLastError = true)]
    436         public static extern UInt32 SendInput(UInt32 nInputs, Input[] pInputs, Int32 cbSize);
    437 
    438         [DllImport("Kernel32.dll", EntryPoint = "GetTickCount", CharSet = CharSet.Auto, SetLastError = true)]
    439         public static extern int GetTickCount();
    440 
    441 
    442         [DllImport("user32.dll", SetLastError = true)]
    443         public static extern bool SetLayeredWindowAttributes(IntPtr hwnd, uint crKey, byte bAlpha, uint dwFlags);
    444 
    445         [DllImport("user32.dll", SetLastError = true)]
    446         public static extern uint SetWindowLong(IntPtr hwnd, int nIndex, uint dwNewLong);
    447 
    448         [DllImport("user32.dll", SetLastError = true)]
    449         public static extern uint GetWindowLong(IntPtr hwnd, int nIndex);
    450 
    451 
    452         [DllImportAttribute("user32.dll", SetLastError = true)]
    453         public static extern int SendMessage(IntPtr hWnd, uint Msg, uint wParam, uint lParam);
    454 
    455         [DllImportAttribute("user32.dll", SetLastError = true)]
    456         public static extern bool ReleaseCapture();
    457 
    458         [DllImport("kernel32.dll", CharSet = CharSet.Auto, SetLastError = true)]
    459         public static extern int GetShortPathName(string lpszLongPath, string shortFile, int cchBuffer);
    460 
    461         [DllImport("winmm.dll", EntryPoint = "mciSendString", CharSet = CharSet.Auto, SetLastError = true)]
    462         public static extern int mciSendString(string lpstrCommand, string lpstrReturnString, int uReturnLength, int hwndCallback);
    463 
    464         [DllImport("advapi32.dll", SetLastError = true, ExactSpelling = true)]
    465         public static extern bool OpenProcessToken(IntPtr h, int acc, ref IntPtr phtok);
    466 
    467         [DllImport("kernel32.dll", ExactSpelling = true, SetLastError = true)]
    468         public static extern IntPtr GetCurrentThread();
    469 
    470         [DllImport("advapi32.dll", ExactSpelling = true, SetLastError = true)]
    471         public static extern bool OpenThreadToken(IntPtr h, int acc, bool openAsSelf, ref IntPtr phtok);
    472 
    473         [DllImport("advapi32.dll", SetLastError = true)]
    474         public static extern bool LookupPrivilegeValue(string host, string name, ref long pluid);
    475 
    476         [DllImport("advapi32.dll", SetLastError = true, ExactSpelling = true)]
    477         public static extern bool AdjustTokenPrivileges(IntPtr htok, bool disall, ref TOKEN_PRIVILEGES newst, int len, IntPtr prev, IntPtr relen);
    478 
    479         [DllImport("user32.dll", SetLastError = true, ExactSpelling = true)]
    480         public static extern bool ExitWindowsEx(int DoFlag, int rea);
    481 
    482         [DllImport("kernel32.dll", CharSet = CharSet.Auto, SetLastError = true)]
    483         public static extern IntPtr GetCurrentProcess();
    484 
    485         [DllImport("kernel32.dll", EntryPoint = "GetLastError")]
    486         public static extern int GetLastError();
    487 
    488         [DllImport("User32.Dll", EntryPoint = "LockWorkStation", SetLastError = true), Description("Locks the workstation's display. Locking a workstation protects it from unauthorized use.")]
    489         [return: MarshalAs(UnmanagedType.Bool)]
    490         public static extern bool LockWorkStation();
    491 
    492         [DllImport("advapi32.dll", SetLastError = true)]
    493         public static extern bool InitiateSystemShutdown(string Machinename, string Message, long Timeout, bool ForceAppsClosed, bool RebootAfterShutdown);
    494 
    495         //Zero Memory
    496         [DllImport("kernel32.dll", SetLastError = true)]
    497         public static extern void ZeroMemory(IntPtr dest, int size);
    498 
    499         //Create file - overloaded
    500         [DllImport("kernel32.dll", CharSet = CharSet.Auto, SetLastError = true)]
    501         public static extern int CreateFile(string lpFileName, int dwDesiredAccess, int dwSharedMode, IntPtr lpSecurityAttributes, int dwCreationDisposition, int dwFlagsandAttributes, int hTemplatFile);
    502 
    503         [DllImport("kernel32.dll", CharSet = CharSet.Auto, SetLastError = true)]
    504         public static extern int CreateFile(string lpFileName, int dwDesiredAccess, int dwSharedMode, ref SECURITY_ATTRIBUTES lpSecurityAttributes, int dwCreationDisposition, int dwFlagsandAttributes, int hTemplatFile);
    505 
    506         //CloseFile
    507         [DllImport("kernel32.dll", CharSet = CharSet.Auto, SetLastError = true)]
    508         public static extern bool CloseHandle(int hHandle);
    509 
    510         //deviceIoControl - overloaded
    511         [DllImport("kernel32.dll", CharSet = CharSet.Auto, SetLastError = true)]
    512         public static extern bool DeviceIoControl(int hDevice, int dwIoControlCode, byte[] InBuffer, int nInBufferSize, byte[] OutBuffer, int nOutputBufferSize, ref int pBytesReturned, int pOverlapped);
    513 
    514         [DllImport("kernel32.dll", CharSet = CharSet.Auto, SetLastError = true)]
    515         public static extern bool DeviceIoControl(int hDevice, int dwIoControlCode, int[] InBuffer, int nInBufferSize, int[] OutBuffer, int nOutputBufferSize, ref int pBytesReturned, int pOverlapped);
    516 
    517         [DllImport("kernel32.dll", CharSet = CharSet.Auto, SetLastError = true)]
    518         public static extern bool DeviceIoControl(
    519            [MarshalAs(UnmanagedType.U4)] int hDevice,
    520            [MarshalAs(UnmanagedType.U4)] int dwIoControlCode, IntPtr lpInBuffer,
    521            [MarshalAs(UnmanagedType.U4)]uint nInBufferSize, IntPtr lpOutBuffer,
    522            [MarshalAs(UnmanagedType.U4)] uint nOutputBufferSize,
    523            [MarshalAs(UnmanagedType.U4)]out int pBytesReturned,
    524            [MarshalAs(UnmanagedType.U4)]int pOverlapped);
    525         [DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
    526         public static extern bool AnimateWindow( IntPtr hwnd, int dwTime, int dwFlags ); 
    527 
    528 
    529     }
    530 }
    View Code
  • 相关阅读:
    Dirichlet distribution【转】
    实现Div层里的文字垂直居中的方法
    Kullback–Leibler divergence相对熵【转】
    判别模型、生成模型与朴素贝叶斯方法【转】
    卸载wine只需简单6个步骤【转】
    在ubuntu11.04通过Wine使用中国知网cnki的CAJview阅读器打开*.nh *.caj后缀的文献资料【转】
    网页制作学习网站收集
    XML数据绑定到Table中
    ubuntu10.04教育网更新源sources.list【转有效的】
    cidaemon.exe导致CPU100%的解决办法
  • 原文地址:https://www.cnblogs.com/CodeBase/p/3399956.html
Copyright © 2020-2023  润新知