public void LoadString() { using (var handle = ModuleMethods.LoadLibrary(GetNativeTestLibraryLocation(), LoadLibraryFlags.LOAD_LIBRARY_AS_IMAGE_RESOURCE | LoadLibraryFlags.LOAD_LIBRARY_AS_DATAFILE)) { string resource = ResourceMethods.LoadString(handle, 101); resource.Should().Be("Test"); } }
/// <summary> /// Get the string from resource. /// </summary> /// <param name="resourceId">String resource ID.</param> /// <returns>String.</returns> /// <exception cref="Win32Exception">Could not load resource DLL.</exception> public string LoadString(int resourceId) { Contract.Ensures(Contract.Result <string>() != null); var hInstance = GetInstanceHandle(); var result = new StringBuilder(255); ResourceMethods.LoadString(hInstance, resourceId, result, result.Capacity); return(result.ToString()); }
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 = ModuleMethods.LoadLibrary(longPathLibrary, LoadLibraryFlags.LOAD_LIBRARY_AS_IMAGE_RESOURCE | LoadLibraryFlags.LOAD_LIBRARY_AS_DATAFILE)) { string resource = ResourceMethods.LoadString(handle, 101); resource.Should().Be("Test"); } } }