我是靠谱客的博主 花痴滑板,最近开发中收集的这篇文章主要介绍【摘自网上】C#.net底层Windows API类-API函数2,觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

C#.net底层Windows API类-API函数2

 

 

[ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success), DllImport("advapi32.dll", SetLastError=true)]    

internal static extern int LsaClose(IntPtr handle);

 

[DllImport("secur32.dll", CharSet=CharSet.Auto, SetLastError=true)]    

internal static extern int LsaConnectUntrusted([In, Out] ref SafeLsaLogonProcessHandle LsaHandle);

 

[ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success), DllImport("secur32.dll", SetLastError=true)]    

internal static extern int LsaDeregisterLogonProcess(IntPtr handle);

 

[ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success), DllImport("advapi32.dll", SetLastError=true)]    

internal static extern int LsaFreeMemory(IntPtr handle);

 

[ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success), DllImport("secur32.dll", SetLastError=true)]    

internal static extern int LsaFreeReturnBuffer(IntPtr handle);

 

[DllImport("secur32.dll", CharSet=CharSet.Auto, SetLastError=true)]    

internal static extern int LsaGetLogonSessionData([In] ref LUID LogonId, [In, Out] ref SafeLsaReturnBufferHandle ppLogonSessionData);

 

[DllImport("secur32.dll", CharSet=CharSet.Auto, SetLastError=true)]    

internal static extern int LsaLogonUser([In] SafeLsaLogonProcessHandle LsaHandle, [In] ref UNICODE_INTPTR_STRING OriginName, [In] uint LogonType, [In] uint AuthenticationPackage, [In] IntPtr AuthenticationInformation, [In] uint AuthenticationInformationLength, [In] IntPtr LocalGroups, [In] ref TOKEN_SOURCE SourceContext, [In, Out] ref SafeLsaReturnBufferHandle ProfileBuffer, [In, Out] ref uint ProfileBufferLength, [In, Out] ref LUID LogonId, [In, Out] ref SafeTokenHandle Token, [In, Out] ref QUOTA_LIMITS Quotas, [In, Out] ref int SubStatus);    

 

[DllImport("secur32.dll", CharSet=CharSet.Auto, SetLastError=true)]    

internal static extern int LsaLookupAuthenticationPackage([In] SafeLsaLogonProcessHandle LsaHandle, [In] ref UNICODE_INTPTR_STRING PackageName, [In, Out] ref uint AuthenticationPackage); 

 

[DllImport("advapi32.dll", CharSet=CharSet.Unicode, SetLastError=true)]    

internal static extern uint LsaLookupNames(SafeLsaPolicyHandle handle, int count, UNICODE_STRING[] names, ref SafeLsaMemoryHandle referencedDomains, ref SafeLsaMemoryHandle sids);  

 

[DllImport("advapi32.dll", CharSet=CharSet.Unicode, SetLastError=true)]    

internal static extern uint LsaLookupNames2(SafeLsaPolicyHandle handle, int flags, int count, UNICODE_STRING[] names, ref SafeLsaMemoryHandle referencedDomains, ref SafeLsaMemoryHandle sids); 

 

[DllImport("advapi32.dll", CharSet=CharSet.Unicode, SetLastError=true)]    

internal static extern uint LsaLookupSids(SafeLsaPolicyHandle handle, int count, IntPtr[] sids, ref SafeLsaMemoryHandle referencedDomains, ref SafeLsaMemoryHandle names); 

 

[DllImport("advapi32.dll", CharSet=CharSet.Unicode, SetLastError=true)]    

internal static extern int LsaNtStatusToWinError([In] int status);    

 

[DllImport("advapi32.dll", CharSet=CharSet.Unicode, SetLastError=true)]    

internal static extern uint LsaOpenPolicy(string systemName, ref LSA_OBJECT_ATTRIBUTES attributes, int accessMask, out SafeLsaPolicyHandle handle);    

 

[DllImport("secur32.dll", CharSet=CharSet.Auto, SetLastError=true)]    

internal static extern int LsaRegisterLogonProcess([In] ref UNICODE_INTPTR_STRING LogonProcessName, [In, Out] ref SafeLsaLogonProcessHandle LsaHandle, [In, Out] ref IntPtr SecurityMode);

 

[DllImport("kernel32.dll", CharSet=CharSet.Auto)]    

internal static extern IntPtr lstrcpy(IntPtr dst, string src);    

 

[DllImport("kernel32.dll", CharSet=CharSet.Auto)]    

internal static extern IntPtr lstrcpy(StringBuilder dst, IntPtr src);    

 

[DllImport("kernel32.dll", CharSet=CharSet.Auto)]    

internal static extern int lstrlen(sbyte[] ptr);  

 

[DllImport("kernel32.dll", CharSet=CharSet.Auto)]    

internal static extern int lstrlen(IntPtr ptr);   

 

[DllImport("kernel32.dll", CharSet=CharSet.Ansi)]    

internal static extern int lstrlenA(IntPtr ptr); 

 

[DllImport("kernel32.dll", CharSet=CharSet.Unicode)]    

internal static extern int lstrlenW(IntPtr ptr);    

internal static int MakeHRFromErrorCode(int errorCode); 

 

[DllImport("kernel32.dll", SetLastError=true, ExactSpelling=true)]    

internal static extern IntPtr MapViewOfFile(SafeFileMappingHandle handle, uint dwDesiredAccess, uint dwFileOffsetHigh, uint dwFileOffsetLow, UIntPtr dwNumerOfBytesToMap);  

 

[DllImport("kernel32.dll", CharSet=CharSet.Auto, SetLastError=true)]    

internal static extern bool MoveFile(string src, string dst);    

 

[DllImport("kernel32.dll", CharSet=CharSet.Auto, SetLastError=true)]   

 internal static extern SafeWaitHandle OpenEvent(int desiredAccess, bool inheritHandle, string name); 

 

[DllImport("kernel32.dll", CharSet=CharSet.Auto, SetLastError=true)]    

internal static extern SafeWaitHandle OpenMutex(int desiredAccess, bool inheritHandle, string name);    

 

[DllImport("advapi32.dll", CharSet=CharSet.Unicode, SetLastError=true)]    

internal static extern bool OpenProcessToken([In] IntPtr ProcessToken, [In] TokenAccessLevels DesiredAccess, [In, Out] ref SafeTokenHandle TokenHandle);  

 

[DllImport("kernel32.dll", SetLastError=true)]    

internal static extern bool PeekConsoleInput(IntPtr hConsoleInput, out InputRecord buffer, int numInputRecords_UseOne, out int numEventsRead);    

 

[DllImport("kernel32.dll", SetLastError=true)]    

internal static extern bool ReadConsoleInput(IntPtr hConsoleInput, out InputRecord buffer, int numInputRecords_UseOne, out int numEventsRead);

 

[DllImport("kernel32.dll", SetLastError=true)]    

internal static extern unsafe bool ReadConsoleOutput(IntPtr hConsoleOutput, CHAR_INFO* pBuffer, COORD bufferSize, COORD bufferCoord, ref SMALL_RECT readRegion); 

 

[DllImport("kernel32.dll", SetLastError=true)]    

internal static extern unsafe int ReadFile(SafeFileHandle handle, byte* bytes, int numBytesToRead, out int numBytesRead, IntPtr mustBeZero);  

 

[DllImport("kernel32.dll", SetLastError=true)]    

internal static extern unsafe int ReadFile(SafeFileHandle handle, byte* bytes, int numBytesToRead, IntPtr numBytesRead_mustBeZero, NativeOverlapped* overlapped); 

 

[DllImport("advapi32.dll", CharSet=CharSet.Auto)]    

internal static extern int RegConnectRegistry(string machineName, SafeRegistryHandle key, out SafeRegistryHandle result); 

 

[DllImport("advapi32.dll", CharSet=CharSet.Auto)]    

internal static extern int RegCreateKeyEx(SafeRegistryHandle hKey, string lpSubKey, int Reserved, string lpClass, int dwOptions, int samDesigner, SECURITY_ATTRIBUTES lpSecurityAttributes, out SafeRegistryHandle hkResult, out int lpdwDisposition);

 

[DllImport("advapi32.dll", CharSet=CharSet.Auto)]    

internal static extern int RegDeleteKey(SafeRegistryHandle hKey, string lpSubKey);

 

[DllImport("advapi32.dll", CharSet=CharSet.Auto)]    

internal static extern int RegDeleteValue(SafeRegistryHandle hKey, string lpValueName); 

 

[DllImport("advapi32.dll", CharSet=CharSet.Auto)]    

internal static extern int RegEnumKeyEx(SafeRegistryHandle hKey, int dwIndex, StringBuilder lpName, out int lpcbName, int[] lpReserved, StringBuilder lpClass, int[] lpcbClass, long[] lpftLastWriteTime);    

 

[DllImport("advapi32.dll", CharSet=CharSet.Auto)]    

internal static extern int RegEnumValue(SafeRegistryHandle hKey, int dwIndex, StringBuilder lpValueName, ref int lpcbValueName, IntPtr lpReserved_MustBeZero, int[] lpType, byte[] lpData, int[] lpcbData);    

[DllImport("advapi32.dll", CharSet=CharSet.Ansi)]    

internal static extern int RegEnumValueA(SafeRegistryHandle hKey, int dwIndex, StringBuilder lpValueName, ref int lpcbValueName, IntPtr lpReserved_MustBeZero, int[] lpType, byte[] lpData, int[] lpcbData);    

 

[DllImport("advapi32.dll")]    

internal static extern int RegFlushKey(SafeRegistryHandle hKey);

 

[DllImport("advapi32.dll", CharSet=CharSet.Auto)]    

internal static extern int RegOpenKeyEx(SafeRegistryHandle hKey, string lpSubKey, int ulOptions, int samDesired, out SafeRegistryHandle hkResult);  

[DllImport("advapi32.dll", CharSet=CharSet.Auto)]    

internal static extern int RegQueryInfoKey(SafeRegistryHandle hKey, StringBuilder lpClass, int[] lpcbClass, IntPtr lpReserved_MustBeZero, ref int lpcSubKeys, int[] lpcbMaxSubKeyLen, int[] lpcbMaxClassLen, ref int lpcValues, int[] lpcbMaxValueNameLen, int[] lpcbMaxValueLen, int[] lpcbSecurityDescriptor, int[] lpftLastWriteTime);   

 

[DllImport("advapi32.dll", CharSet=CharSet.Auto)]    

internal static extern int RegQueryValueEx(SafeRegistryHandle hKey, string lpValueName, int[] lpReserved, ref int lpType, ref int lpData, ref int lpcbData);    

 

[DllImport("advapi32.dll", CharSet=CharSet.Auto)]    

internal static extern int RegQueryValueEx(SafeRegistryHandle hKey, string lpValueName, int[] lpReserved, ref int lpType, ref long lpData, ref int lpcbData);    

 

[DllImport("advapi32.dll", CharSet=CharSet.Auto)]    

internal static extern int RegQueryValueEx(SafeRegistryHandle hKey, string lpValueName, int[] lpReserved, ref int lpType, [Out] byte[] lpData, ref int lpcbData);    

 

[DllImport("advapi32.dll", CharSet=CharSet.Auto)]   

internal static extern int RegQueryValueEx(SafeRegistryHandle hKey, string lpValueName, int[] lpReserved, ref int lpType, [Out] char[] lpData, ref int lpcbData);    

 

[DllImport("advapi32.dll", CharSet=CharSet.Auto)]    

internal static extern int RegQueryValueEx(SafeRegistryHandle hKey, string lpValueName, int[] lpReserved, ref int lpType, StringBuilder lpData, ref int lpcbData);    

 

[DllImport("advapi32.dll", CharSet=CharSet.Auto)]    

internal static extern int RegSetValueEx(SafeRegistryHandle hKey, string lpValueName, int Reserved, RegistryValueKind dwType, byte[] lpData, int cbData);  

[DllImport("advapi32.dll", CharSet=CharSet.Auto)]  

internal static extern int RegSetValueEx(SafeRegistryHandle hKey, string lpValueName, int Reserved, RegistryValueKind dwType, string lpData, int cbData);  

[DllImport("advapi32.dll", CharSet=CharSet.Auto)]    

internal static extern int RegSetValueEx(SafeRegistryHandle hKey, string lpValueName, int Reserved, RegistryValueKind dwType, ref int lpData, int cbData); 

[DllImport("advapi32.dll", CharSet=CharSet.Auto)]    

internal static extern int RegSetValueEx(SafeRegistryHandle hKey, string lpValueName, int Reserved, RegistryValueKind dwType, ref long lpData, int cbData);

 

[ReliabilityContract(Consistency.WillNotCorruptState, Cer.MayFail), DllImport("kernel32.dll", SetLastError=true)]    

internal static extern bool ReleaseMutex(SafeWaitHandle handle);    

 

[DllImport("kernel32.dll", CharSet=CharSet.Auto, SetLastError=true)]    

internal static extern bool RemoveDirectory(string path);    

 

[DllImport("kernel32.dll", CharSet=CharSet.Auto, SetLastError=true)]    

internal static extern bool ReplaceFile(string replacedFileName, string replacementFileName, string backupFileName, int dwReplaceFlags, IntPtr lpExclude, IntPtr lpReserved);    

 

[DllImport("kernel32.dll", SetLastError=true)]    

internal static extern bool ResetEvent(SafeWaitHandle handle);    

internal static SafeFileHandle SafeCreateFile(string lpFileName, int dwDesiredAccess, FileShare dwShareMode, SECURITY_ATTRIBUTES securityAttrs, FileMode dwCreationDisposition, int dwFlagsAndAttributes, IntPtr hTemplateFile);    

 

[DllImport("user32.dll", SetLastError=true)]    

internal static extern IntPtr SendMessageTimeout(IntPtr hWnd, int Msg, IntPtr wParam, string lParam, uint fuFlags, uint uTimeout, IntPtr lpdwResult);  

[DllImport("kernel32.dll", SetLastError=true)]    

internal static extern bool SetConsoleCP(uint codePage); 

 

[ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success), DllImport("kernel32.dll", SetLastError=true)]    internal static extern bool SetConsoleCtrlHandler(ConsoleCtrlHandlerRoutine handler, bool addOrRemove);    

 

[DllImport("kernel32.dll", SetLastError=true)]    

internal static extern bool SetConsoleCursorInfo(IntPtr hConsoleOutput, ref CONSOLE_CURSOR_INFO cci);    

 

[DllImport("kernel32.dll", SetLastError=true)]    

internal static extern bool SetConsoleCursorPosition(IntPtr hConsoleOutput, COORD cursorPosition);    

 

[DllImport("kernel32.dll", SetLastError=true)]    

internal static extern bool SetConsoleMode(IntPtr hConsoleHandle, int mode);    

 

[DllImport("kernel32.dll", SetLastError=true)]    

internal static extern bool SetConsoleOutputCP(uint codePage);    

 

[DllImport("kernel32.dll", SetLastError=true)]    

internal static extern bool SetConsoleScreenBufferSize(IntPtr hConsoleOutput, COORD size);  

 

[DllImport("kernel32.dll", SetLastError=true)]    

internal static extern bool SetConsoleTextAttribute(IntPtr hConsoleOutput, short attributes);    

 

[DllImport("kernel32.dll", CharSet=CharSet.Auto, SetLastError=true)]    

internal static extern bool SetConsoleTitle(string title);    

 

[DllImport("kernel32.dll", SetLastError=true)]    

internal static extern unsafe bool SetConsoleWindowInfo(IntPtr hConsoleOutput, bool absolute, SMALL_RECT* consoleWindow);

 

[DllImport("kernel32.dll", CharSet=CharSet.Auto, SetLastError=true)]    

internal static extern bool SetCurrentDirectory(string path);    

 

[DllImport("kernel32.dll", SetLastError=true)]    

internal static extern bool SetEndOfFile(SafeFileHandle hFile); 

 

[DllImport("kernel32.dll", CharSet=CharSet.Auto, SetLastError=true)]    

internal static extern bool SetEnvironmentVariable(string lpName, string lpValue);  

 

[DllImport("kernel32.dll")]    

internal static extern int SetErrorMode(int newMode);    

 

[DllImport("kernel32.dll", SetLastError=true)]    

internal static extern bool SetEvent(SafeWaitHandle handle); 

 

[DllImport("kernel32.dll", CharSet=CharSet.Auto, SetLastError=true)]    

internal static extern bool SetFileAttributes(string name, int attr);    

internal static long SetFilePointer(SafeFileHandle handle, long offset, SeekOrigin origin, out int hr); 

 

[DllImport("kernel32.dll", EntryPoint="SetFilePointer", SetLastError=true)]    

private static extern unsafe int SetFilePointerWin32(SafeFileHandle handle, int lo, int* hi, int origin);

 

[DllImport("kernel32.dll", SetLastError=true)]    

internal static extern unsafe bool SetFileTime(SafeFileHandle hFile, FILE_TIME* creationTime, FILE_TIME* lastAccessTime, FILE_TIME* lastWriteTime); 

 

[DllImport("kernel32.dll", SetLastError=true)]    

internal static extern void SetLastError(int errorCode);    

 

[DllImport("advapi32.dll", EntryPoint="SetSecurityInfo", CharSet=CharSet.Unicode, SetLastError=true)]    

internal static extern uint SetSecurityInfoByHandle(SafeHandle handle, uint objectType, uint securityInformation, byte[] owner, byte[] group, byte[] dacl, byte[] sacl); 

 

[DllImport("advapi32.dll", EntryPoint="SetNamedSecurityInfoW", CharSet=CharSet.Unicode, SetLastError=true)]    

internal static extern uint SetSecurityInfoByName(string name, uint objectType, uint securityInformation, byte[] owner, byte[] group, byte[] dacl, byte[] sacl);    

 

[DllImport("kernel32.dll", CharSet=CharSet.Auto, SetLastError=true)]    

internal static extern bool SetVolumeLabel(string driveLetter, string volumeName); 

 

[DllImport("shfolder.dll", CharSet=CharSet.Auto)]    

internal static extern int SHGetFolderPath(IntPtr hwndOwner, int nFolder, IntPtr hToken, int dwFlags, StringBuilder lpszPath); 

 

[ReliabilityContract(Consistency.WillNotCorruptState, Cer.MayFail), DllImport("oleaut32.dll", CharSet=CharSet.Unicode)]    

internal static extern IntPtr SysAllocStringLen(string src, int len);  

[ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success), DllImport("oleaut32.dll")]    

internal static extern void SysFreeString(IntPtr bstr);    

 

[ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success), DllImport("oleaut32.dll")]    

internal static extern int SysStringLen(IntPtr bstr);    

 

[ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success), DllImport("advapi32.dll", CharSet=CharSet.Unicode, SetLastError=true)]    

internal static extern int SystemFunction040([In, Out] SafeBSTRHandle pDataIn, [In] uint cbDataIn, [In] uint dwFlags);    

 

[DllImport("advapi32.dll", CharSet=CharSet.Unicode, SetLastError=true)]    

internal static extern int SystemFunction041([In, Out] SafeBSTRHandle pDataIn, [In] uint cbDataIn, [In] uint dwFlags); 

 

[DllImport("kernel32.dll", SetLastError=true)]    

internal static extern bool UnlockFile(SafeFileHandle handle, int offsetLow, int offsetHigh, int countLow, int countHigh);

 

[ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success), DllImport("kernel32.dll", ExactSpelling=true)]    

internal static extern bool UnmapViewOfFile(IntPtr lpBaseAddress);    

internal static SafeFileHandle UnsafeCreateFile(string lpFileName, int dwDesiredAccess, FileShare dwShareMode, SECURITY_ATTRIBUTES securityAttrs, FileMode dwCreationDisposition, int dwFlagsAndAttributes, IntPtr hTemplateFile);    

 

[ReliabilityContract(Consistency.WillNotCorruptState, Cer.MayFail), DllImport("kernel32.dll", SetLastError=true)]    

internal static extern unsafe void* VirtualAlloc(void* address, UIntPtr numBytes, int commitOrReserve, int pageProtectionMode);    

 

[ReliabilityContract(Consistency.WillNotCorruptState, Cer.MayFail), DllImport("kernel32.dll", SetLastError=true)]    

internal static extern unsafe bool VirtualFree(void* address, UIntPtr numBytes, int pageFreeMode);    

 

[DllImport("kernel32.dll", SetLastError=true)]    

internal static extern unsafe IntPtr VirtualQuery(void* address, ref MEMORY_BASIC_INFORMATION buffer, IntPtr sizeOfBuffer);  

 

[DllImport("kernel32.dll", SetLastError=true)]    

internal static extern uint WaitForMultipleObjects(uint nCount, IntPtr[] handles, bool bWaitAll, uint dwMilliseconds);   

 

[DllImport("kernel32.dll")]    

internal static extern unsafe int WideCharToMultiByte(uint cp, uint flags, char* pwzSource, int cchSource, byte* pbDestBuffer, int cbDestBuffer, IntPtr null1, IntPtr null2);    

 

[DllImport("kernel32.dll", SetLastError=true)]    

internal static extern unsafe bool WriteConsoleOutput(IntPtr hConsoleOutput, CHAR_INFO* buffer, COORD bufferSize, COORD bufferCoord, ref SMALL_RECT writeRegion);    

 

[DllImport("kernel32.dll", SetLastError=true)]    

internal static extern unsafe int WriteFile(SafeFileHandle handle, byte* bytes, int numBytesToWrite, out int numBytesWritten, IntPtr mustBeZero);    

 

[DllImport("kernel32.dll", SetLastError=true)]    

internal static extern unsafe int WriteFile(SafeFileHandle handle, byte* bytes, int numBytesToWrite, IntPtr numBytesWritten_mustBeZero, NativeOverlapped* lpOverlapped);    

 

[ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success), DllImport("kernel32.dll", SetLastError=true)]    

internal static extern void ZeroMemory(IntPtr handle, uint length);

 

最后

以上就是花痴滑板为你收集整理的【摘自网上】C#.net底层Windows API类-API函数2的全部内容,希望文章能够帮你解决【摘自网上】C#.net底层Windows API类-API函数2所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(79)

评论列表共有 0 条评论

立即
投稿
返回
顶部