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;

}

目录
相关文章
mvc.net分页查询案例——DLL数据访问层(HouseDLL.cs)
mvc.net分页查询案例——DLL数据访问层(HouseDLL.cs)
【Azure Key Vault】.NET 代码如何访问中国区的Key Vault中的机密信息(Get/Set Secret)
【Azure Key Vault】.NET 代码如何访问中国区的Key Vault中的机密信息(Get/Set Secret)
267 3
|
存储 C++
C++ dll 传 string 类 问题
C++ dll 传 string 类 问题
281 0
|
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
333 0
|
JavaScript
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
350 0
|
JavaScript 前端开发 API
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
VS2013、VS2005都是MD,跨dll使用stl的string崩溃问题
VS2013、VS2005都是MD,跨dll使用stl的string崩溃问题
|
人工智能
CF1660C Get an Even String(贪心)
CF1660C Get an Even String(贪心)
278 0