Get text from dll using index

How can I get strings from windows dlls like mssvp.dll and themeui.dll using an index? There are several lines in the registry or theme files (for example, DisplayName in the themes) that point to the dll and index number instead of real texts. For example, I have: DisplayName = @% SystemRoot% \ System32 \ themeui.dll, -2106 in a Windows theme file. So, how can I get real strings from these dlls using C # and .Net 4.0?

+4
source share
1 answer

You need to use P / Invoke:

/// <summary>Returns a string resource from a DLL.</summary> /// <param name="DLLHandle">The handle of the DLL (from LoadLibrary()).</param> /// <param name="ResID">The resource ID.</param> /// <returns>The name from the DLL.</returns> static string GetStringResource(IntPtr handle, uint resourceId) { StringBuilder buffer = new StringBuilder(8192); //Buffer for output from LoadString() int length = NativeMethods.LoadString(handle, resourceId, buffer, buffer.Capacity); return buffer.ToString(0, length); //Return the part of the buffer that was used. } static class NativeMethods { [DllImport("kernel32.dll", CharSet = CharSet.Auto, SetLastError = true, BestFitMapping = false, ThrowOnUnmappableChar = true)] internal static extern IntPtr LoadLibrary(string lpLibFileName); [DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true, BestFitMapping = false, ThrowOnUnmappableChar = true)] internal static extern int LoadString(IntPtr hInstance, uint wID, StringBuilder lpBuffer, int nBufferMax); [DllImport("kernel32.dll")] public static extern int FreeLibrary(IntPtr hLibModule); } 
+5
source

Source: https://habr.com/ru/post/1498066/


All Articles