如何從使用索引的mssvp.dll和themeui.dll等windows dll獲取字符串? 在註冊表或主題文件中,有一些字符串(如主題中的DisplayName)指向一個dll和一個索引號,而不是真實的文本。例如我有: DisplayName = @%SystemRoot%\ System32 \ themeui.dll,-2106在Windows主題文件中。那麼,如何使用C#和.Net 4.0從那些DLL中檢索真正的字符串呢?使用索引從dll中獲取文本
4
A
回答
5
您需要使用的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);
}
相關問題
- 1. 從文本框獲取索引C#
- 2. 從vb2005中的文本搜索中獲取索引列表
- 3. Java腳本從文本框中獲取數組的索引號
- 4. 如何使用List中的特定文本獲取索引?
- 5. 從另一個文本文件中獲取文本文件的索引
- 6. 從索引中獲取文本多選Jquery
- 7. 如何從Tkinter文本框中獲取索引
- 8. AnkhSVN在獲取最新版本時未獲取引用dll
- 9. ArrayList,獲取值,從索引()到索引()
- 10. 從索引獲取價值與索引
- 11. 從Tkinter項目搜索框中使用按鈕獲取文本
- 12. 使用JEditorPane獲取選定文本的索引
- 13. 使用純js獲取所選文本字段的索引
- 14. 使用OLE從Powerpoint中獲取文本
- 15. 獲取引用文本
- 16. 爲elasticsearch索引解析文本並獲取索引值
- 17. 使用Ruby/Rails從Apache索引頁獲取文件列表
- 18. 從IndexColorModel獲取索引?
- 19. 從Joptionpane獲取索引
- 20. 從對象獲取索引
- 21. 如何使用oracle文本索引從json提取數據
- 22. 從solr和nutch生成的搜索索引中獲取文本片段
- 23. jQuery中獲取使用索引()的元素的索引
- 24. Postgres不會從文本/ varchar列獲取索引
- 25. ArangoDB獲取文檔索引
- 26. 從DLL中獲取HModule
- 27. 使用文本索引從PDF文件中提取特定數據以找到
- 28. 從MonoTouch中引用的DLL獲取執行程序集名稱?
- 29. 從列表列表中獲取索引
- 30. 如何從表中獲取索引值?
@SriramSakthivel:無;他想知道如何從DLL的字符串表中獲取字符串。他將需要P/Invoke。 – SLaks
@SLaks啊,我剛纔意識到.. –
使用LoadLibrary()加載DLL,LoadString()從資源表中加載字符串,FreeLibrary()再次卸載DLL。翻轉資源號碼上的標誌。訪問pinvoke.net網站獲取pinvoke聲明。 –