In C #, use Windows API functions to read string Resources in the standard Win32 DLL file
The following code reads a string resource whose ID number is 712 In the user32.dll file.
If the code runs normally, you can see
/*
Other people are logged on to this remote computer. shutting down windows might cause them to lose data. also, someone at the remote location will have to restart the computer manually. /R/n/R/Ndo you want to continue shutting down?
For the Chinese version of XP, the strings here are different
*/
Using system;
Using system. Collections. Generic;
Using system. Windows. forms;
Using system. runtime. interopservices;
Using system. text;
Namespace loadlibrary
{
Public static class Program
{
[Dllimport ("kernel32.dll", entrypoint = "loadlibrarya")]
Public static extern intptr loadlibrary (string slibname );
[Dllimport ("kernel32.dll", entrypoint = "freelibrary")]
Public static extern int freelibrary (intptr hlib );
[Dllimport ("user32.dll", entrypoint = "loadstringw", charset = charset. ANSI)]
Public static extern int loadstring (intptr hlib, uint resid, byte [] Buf, int bufsize );
[Stathread]
Static void main (string [] ARGs ){
Intptr hdll = loadlibrary ("user32.dll ");
If (hdll = intptr. Zero ){
MessageBox. Show ("can't load library! ");
Return;
}
Byte [] sb = new byte [1024];
Int ret = 0;
Ret = loadstring (hdll, 712, Sb, 1025 );
If (ret = 0 ){
MessageBox. Show ("string resource 712 is not found! ");
Freelibrary (hdll );
Return;
}
MessageBox. Show ("string resource 100:" + encoding. Unicode. getstring (SB). Replace ("/0 ",""));
Freelibrary (hdll );
Return;
}
}
}
// Running environment: passed in vs2008 (. net2.0)