internal static DelegateType GetFunctionDelegate <DelegateType>(SafeLibraryHandle library, string methodName) { IntPtr method = Private.GetProcAddress(library, methodName); if (method == IntPtr.Zero) { int error = Marshal.GetLastWin32Error(); throw GetIoExceptionForError(error, methodName); } return((DelegateType)(object)Marshal.GetDelegateForFunctionPointer(method, typeof(DelegateType))); }
unsafe internal static string LoadString(SafeLibraryHandle library, int identifier) { // Passing 0 will give us a read only handle to the string resource char *buffer; int result = Private.LoadStringW(library, identifier, out buffer, 0); if (result <= 0) { int error = Marshal.GetLastWin32Error(); throw GetIoExceptionForError(error, identifier.ToString()); } // Null is not included in the result return(new string(buffer, 0, result)); }
internal static extern IntPtr GetProcAddress( SafeLibraryHandle hModule, [MarshalAs(UnmanagedType.LPStr)] string methodName);
//[DllImport("ntdll.dll", SetLastError = true)] //public static extern uint NtQueryObject(IntPtr handle, ObjectInformationClass objectInformationClass, // IntPtr objectInformation, uint objectInformationLength, out uint returnLength); internal static bool FreeLibrary(SafeLibraryHandle handle) { return(Private.FreeLibrary(handle.DangerousGetHandle())); }
unsafe internal static extern int LoadStringW( SafeLibraryHandle hInstance, int uID, out char *lpBuffer, int nBufferMax);