Use getfileversioninfo to obtain various resources of EXE or DLL.

Source: Internet
Author: User
Tags 04x

There are a lot of online resources to be searched, but none of them can be used by code. Sorry. I have read the msdn document and finally wrote the following code. The Code has passed the test. If you have any questions, please send me an email. Thank you!

Struct langandcodepage
{
Word wlanguage;
Word wcodepage;
} * Lptranslate;

Void getinfofromeanddll (pctstr pcszfilename)
{
DWORD dwsize = 0;
Uint uisize = getfileversioninfosize (pcszfilename, & dwsize );
 
If (0 = uisize)
{
// 0 indicates that the call to the getfileversioninfosize function fails.
Return;
}

Ptstr pbuffer = new tchar [uisize];
 
If (null = pbuffer)
{
// Failed to allocate memory :)
Return;
}

Memset (void *) pbuffer, 0, uisize );

// Obtain the resource information of EXE or DLL and store it in pbuffer.
If (! Getfileversioninfo (pcszfilename, 0, uisize, (pvoid) pbuffer ))
{
// Getfileversioninfo call failed.
Return;
}

Langandcodepage * planguage = NULL; // This setting does not matter.

Uint uiothersize = 0;
// Obtain resource-related codePage and language
If (! Verqueryvalue (pbuffer, _ T ("// varfileinfo // translation "),
(Pvoid *) & planguage, & uiothersize ))
{
// Error
Return;
}
 
//////////////////////////////////////// //////////////////////////////////
//////////////////////////////////////// //////////////////////////////////
// Super important

Pvoid pTMP = NULL; // you must set the pTMP variable to pvoid or lpvoid
// Otherwise, information cannot be obtained. You can try it if you don't believe it.
// Tchar * pTMP = NULL;
// Or the following settings
// Tchar pTMP [max_path];
// Memset (void *) pTMP, 0, sizeof (pTMP ));

//////////////////////////////////////// //////////////////////////////////
//////////////////////////////////////// //////////////////////////////////

Tchar subblock [max_path];
Memset (void *) subblock, 0, sizeof (subblock ));

For (uint I = 0; I <(uiothersize/sizeof (langandcodepage); I ++)
{
// Obtain information about each codePage and language resource.
Wsprintf (subblock,
Text ("// stringfileinfo // % 04x % 04x // originalfilename "),
Planguage [I]. wlanguage,
Planguage [I]. wcodepage );

// Comments internalname productname
// CompanyName legalcopyright productversion
// Filedescription legaltrademarks privatebuild
// Fileversion originalfilename specialbuild

// Originalfilename can be replaced by the above.

// Retrieve file description for language and code page "I ".
Verqueryvalue (pbuffer,
Subblock,
(Pvoid *) & pTMP,
& Uiothersize );
Tchar choriginalfilename [max_path];
Memset (void *) choriginalfilename, 0, sizeof (choriginalfilename ));
_ Tcscpy (choriginalfilename, (tchar *) pTMP );
MessageBox (null, choriginalfilename, _ T ("succeed! "), Mb_ OK );
}
Delete [] pbuffer;
Pbuffer = NULL;
}

Enter version. Lib in the object/library modules of Project> Settings> linking.

Of course, the header file must be added with # include <tchar. h>

And # include <windows. h>

Nothing else. Hope to help you.

 

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.