get string from win32 dll in .NET

简介: using System; using System.Runtime.InteropServices;   [DllImport("kernel32")] public static extern IntPtr LoadLibr...

using System;

using System.Runtime.InteropServices;

 

[DllImport("kernel32")]

public static extern IntPtr LoadLibrary(string lpFileName);

[DllImport("kernel32")]

public static extern Boolean FreeLibrary(IntPtr hResModule);

 [DllImport("user32.dll", CharSet = CharSet.Unicode, EntryPoint = "LoadStringW", ExactSpelling = true)]

public static extern int LoadString(

IntPtr hInstance,

uint uID,

StringBuilder lpBuffer,

int nBufferMax);

 

public static String GetStringResource(IntPtr hModuleInstance, uint uiStringID)

{

StringBuilder sb = new StringBuilder(255);

            LoadString(hModuleInstance, uiStringID, sb, sb.Capacity + 1);

return sb.ToString();

}

public static string GetWin32Resource(string componentName, uint uiResourceId)

{

            string str = string.Empty;

            IntPtr hMod = LoadLibrary(@"***\test.dll");

     if (hMod != null)

            {

                str = GetStringResource(hMod, uiResourceId);

                FreeLibrary(hMod);

            }

     return str;

}

目录
打赏
0
0
0
0
20
分享
相关文章
|
10月前
mvc.net分页查询案例——DLL数据访问层(HouseDLL.cs)
mvc.net分页查询案例——DLL数据访问层(HouseDLL.cs)
|
7月前
|
API
【Azure Key Vault】.NET 代码如何访问中国区的Key Vault中的机密信息(Get/Set Secret)
【Azure Key Vault】.NET 代码如何访问中国区的Key Vault中的机密信息(Get/Set Secret)
|
7月前
|
C++ dll 传 string 类 问题
C++ dll 传 string 类 问题
61 0
|
7月前
|
SQL
Typecho——Argument 1 passed to Typecho\Router::get() must be of the type string
Typecho——Argument 1 passed to Typecho\Router::get() must be of the type string
79 0
|
10月前
|
GET http://192.168.2.198:8080/sockjs-node/info?t=1626862752216 net::ERR_CONNECTION_TIMED_OUT
GET http://192.168.2.198:8080/sockjs-node/info?t=1626862752216 net::ERR_CONNECTION_TIMED_OUT
92 0
Vue报错:sockjs.js?9be2:1627 GET http://192.168.43.88:8080/sockjs-node/info?t=1631603986586 net::ERR_CO
Vue报错:sockjs.js?9be2:1627 GET http://192.168.43.88:8080/sockjs-node/info?t=1631603986586 net::ERR_CO
CF1660C Get an Even String(贪心)
CF1660C Get an Even String(贪心)
112 0

热门文章

最新文章

AI助理

你好,我是AI助理

可以解答问题、推荐解决方案等