C # Read string resources from Win32 standard DLL files

Source: Internet
Author: User

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)

 

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.