public void LoadAsBinary() { using (var handle = ModuleDesktopMethods.LoadLibrary(GetNativeTestLibraryLocation(), 0)) { handle.IsInvalid.Should().BeFalse(); } }
public void LoadAsResource() { using (var handle = ModuleDesktopMethods.LoadLibrary(GetNativeTestLibraryLocation(), LoadLibraryFlags.LOAD_LIBRARY_AS_IMAGE_RESOURCE | LoadLibraryFlags.LOAD_LIBRARY_AS_DATAFILE)) { handle.IsInvalid.Should().BeFalse(); } }
public void LoadFunction() { using (var handle = ModuleDesktopMethods.LoadLibrary(GetNativeTestLibraryLocation(), LoadLibraryFlags.LOAD_WITH_ALTERED_SEARCH_PATH)) { var doubler = ModuleDesktopMethods.GetFunctionDelegate <DoubleDelegate>(handle, "Double"); doubler(2).Should().Be(4); } }
public void GetProcessModulePaths() { var modules = ModuleDesktopMethods.GetProcessModules(); var moduleNames = (from module in modules select ModuleDesktopMethods.GetModuleFileName(module)).ToArray(); moduleNames.Should().NotBeEmpty(); moduleNames.Length.Should().Be(modules.Count()); }
public void LoadString() { using (var handle = ModuleDesktopMethods.LoadLibrary(GetNativeTestLibraryLocation(), LoadLibraryFlags.LOAD_LIBRARY_AS_IMAGE_RESOURCE | LoadLibraryFlags.LOAD_LIBRARY_AS_DATAFILE)) { string resource = ResourceDesktopMethods.LoadString(handle, 101); resource.Should().Be("Test"); } }
public void GetEntryModuleInfo() { var module = ModuleDesktopMethods.GetModuleHandle(null); module.Should().NotBe(ModuleTypes.ModuleHandle.NullModuleHandle); var info = ModuleDesktopMethods.GetModuleInfo(module); info.lpBaseOfDll.Should().Be(module.HMODULE); }
public void GetEntryModuleHandleAndFileName() { var module = ModuleDesktopMethods.GetModuleHandle(null); module.Should().NotBe(ModuleTypes.ModuleHandle.NullModuleHandle); string pathByHandle = ModuleDesktopMethods.GetModuleFileName(module); pathByHandle.Should().NotBeNullOrWhiteSpace(); string pathByDefault = ModuleDesktopMethods.GetModuleFileName(ModuleTypes.ModuleHandle.NullModuleHandle); // Strangely the path is cased differently when getting the module file name through GetModuleFileNameEx, but not GetModuleFileName. pathByHandle.Should().BeEquivalentTo(pathByDefault); }
public void LoadAsBinaryFromLongPath() { using (var cleaner = new TestFileCleaner()) { string longPath = @"\\?\" + PathGenerator.CreatePathOfLength(cleaner.TempFolder, 500); FileHelper.CreateDirectoryRecursive(longPath); string longPathLibrary = Paths.Combine(longPath, "LoadAsBinaryFromLongPath.dll"); FileMethods.CopyFile(GetNativeTestLibraryLocation(), longPathLibrary); using (var handle = ModuleDesktopMethods.LoadLibrary(longPathLibrary, LoadLibraryFlags.LOAD_WITH_ALTERED_SEARCH_PATH)) { handle.IsInvalid.Should().BeFalse(); } } }
public void LoadFunctionFromLongPath() { using (var cleaner = new TestFileCleaner()) { string longPath = @"\\?\" + PathGenerator.CreatePathOfLength(cleaner.TempFolder, 500); FileHelper.CreateDirectoryRecursive(longPath); string longPathLibrary = Paths.Combine(longPath, "LoadFunctionFromLongPath.dll"); FileMethods.CopyFile(GetNativeTestLibraryLocation(), longPathLibrary); using (var handle = ModuleDesktopMethods.LoadLibrary(longPathLibrary, 0)) { var doubler = ModuleDesktopMethods.GetFunctionDelegate <DoubleDelegate>(handle, "Double"); doubler(2).Should().Be(4); } } }
public void LoadStringFromLongPath() { using (var cleaner = new TestFileCleaner()) { string longPath = @"\\?\" + PathGenerator.CreatePathOfLength(cleaner.TempFolder, 500); FileHelper.CreateDirectoryRecursive(longPath); string longPathLibrary = Paths.Combine(longPath, "LoadStringFromLongPath.dll"); FileMethods.CopyFile(GetNativeTestLibraryLocation(), longPathLibrary); using (var handle = ModuleDesktopMethods.LoadLibrary(longPathLibrary, LoadLibraryFlags.LOAD_LIBRARY_AS_IMAGE_RESOURCE | LoadLibraryFlags.LOAD_LIBRARY_AS_DATAFILE)) { string resource = ResourceDesktopMethods.LoadString(handle, 101); resource.Should().Be("Test"); } } }
public void GetProcessModules() { var modules = ModuleDesktopMethods.GetProcessModules(); modules.Should().NotBeEmpty(); }
public void GetEntryModuleFileName() { string path = ModuleDesktopMethods.GetModuleFileName(ModuleTypes.ModuleHandle.NullModuleHandle); path.Should().NotBeNullOrWhiteSpace(); }
protected override bool ReleaseHandle() { ModuleDesktopMethods.FreeLibrary(handle); handle = IntPtr.Zero; return(true); }