天天看点

get string from win32 dll in .NET

using System;

using System.Runtime.InteropServices;

[DllImport("kernel32")]

public

static

extern

IntPtr

LoadLibrary(string

lpFileName);

Boolean

FreeLibrary(IntPtr

hResModule);

 [DllImport("user32.dll",

CharSet = CharSet.Unicode,

EntryPoint = "LoadStringW",

ExactSpelling = true)]

int

LoadString(

hInstance,

uint

uID,

StringBuilder

lpBuffer,

nBufferMax);

String

GetStringResource(IntPtr

hModuleInstance, uint

uiStringID)

{

sb = new

StringBuilder(255);

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

return

sb.ToString();

}

public static

string

GetWin32Resource(string

componentName, uint

uiResourceId)

str = string.Empty;

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

     if (hMod !=

null)

            {

                str = GetStringResource(hMod, uiResourceId);

                FreeLibrary(hMod);

            }

     return

str;

继续阅读