|
|
|
|
|
Home
»
Win32 API
»
How to get version information of DLLs and Exes?
|
|
|
|
Page Views :
|
10044
|
|
Downloads :
|
0
|
|
Rating :
|
Rate it
|
|
Level :
|
Beginner
|
|
Some times you really wanted to know what is the version of your DLL or EXE which you are using. Microsoft supports couple of API's.The main API is GetFileVersionInfo
GetFileVersionInfo
The GetFileVersionInfo function returns version information about a specified file.
As with other file installation functions, GetFileVersionInfo works only with Win32 file images. It does not work with 16-bit Windows file images.
BOOL GetFileVersionInfo ( LPTSTR lptstrFilename, // pointer to filename string DWORD dwHandle , // ignored DWORD dwLen, // size of buffer LPVOID lpData // pointer to buffer to receive // file-version info. );
In order to Use this API you have to do following.
Add these lines at Top of your file.
struct FileInfo { CString fileName; CString version; CString date; }; struct LANGANDCODEPAGE { WORD wLanguage; WORD wCodePage; }; #define VERINFO_comments "comments" #define VERINFO_CompanyName "CompanyName" #define VERINFO_FileDescrib "FileDescription" #define VERINFO_FileVersion "FileVersion" #define VERINFO_InternalName "InternalName" #define VERINFO_LegalCopyright "LegalCopyright" #define VERINFO_LegalTrademarks "LegalTrademarks" #define VERINFO_OriginalFilename "OriginalFilename" #define VERINFO_ProductName "ProductName" #define VERINFO_ProductVersion "ProductVersion" #define VERINFO_PrivateBuild "PrivateBuild" #define VERINFO_SpecialBuild "SpecialBuild" CString GetFileVersionInfoString(LPCSTR fileFullName,LPCSTR verInfoString);
Implement the function GetFileVersionInfoString
CString GetFileVersionInfoString(LPCSTR fileFullName,LPCSTR verInfoString) { char *rcData = 0; DWORD dwSize; UINT wSize; LANGANDCODEPAGE *lpTranslate; LPTSTR fileName = (LPTSTR)fileFullName; //file name and path CFileStatus status; CString verInfo = "Unavailable"; if( CFile::GetStatus(fileName, status ) ) { //Version LPDWORD handle1 = 0; dwSize = ::GetFileVersionInfoSize(fileName, handle1); if (! dwSize) return verInfo; rcData = new char[dwSize]; // get valid resource data using path, handle, and size int result = ::GetFileVersionInfo(fileName, 0, dwSize, (LPVOID)rcData); if (result) { result = ::VerQueryValue(rcData,TEXT("\\VarFileInfo\\Translation" ), (LPVOID*)&lpTranslate, &wSize); if (result == 0 || wSize == 0) { delete []rcData; return verInfo; } } // Read the file description for each language and code page. char SubBlock[100]; LPVOID lpBuffer; for( unsigned i=0; i < (wSize/sizeof(struct LANGANDCODEPAGE)); i++ ) { wsprintf( SubBlock, TEXT("\\StringFileInfo\\%04x%04x\\%s"), lpTranslate[i].wLanguage,lpTranslate[i].wCodePage,verInfoString); result = VerQueryValue(rcData, SubBlock, (LPVOID*)&lpBuffer, &wSize); if (!result) break; verInfo = (LPCSTR)lpBuffer; } delete []rcData; } return verInfo; }
After Defining this function You can call this function is like
CString ver = "Unavailable"; CString fullFilename; fullFilename = TEXT("C:\\Winnt\\system32\\shell.dll"); ver = GetFileVersionInfoString(fullFilename,VERINFO_FileVersion); AfxMessageBox(ver);
The Message box will show the version no for shell.dll.You can also get copyright Information with same way.
|
|
Comment Request!
Thank you for reading this post. Please post your feedback, question, or comments about this post
Here.
|
|
|
|
|
Login
to add your contents and source code to this article
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
C# Consulting is founded in 2002 by the founders of C# Corner. Unlike a traditional
consulting company, our consultants are well-known experts in .NET and many of them
are MVPs, authors, and trainers. We specialize in Microsoft .NET development and
utilize Agile Development and Extreme Programming practices to provide fast pace
quick turnaround results. Our software development model is a mix of Agile Development,
traditional SDLC, and Waterfall models.
|
|
Click here to learn more about C# Consulting. |
|
|
|
|
|
|
|
Introducing MaxV - one click. infinite control. Hyper-V Hosting from MaximumASP.
Finally – a virtual platform that delivers next-generation Windows Server 2008 Hyper-V virtualization technology from a managed hosting partner you can truly depend on. Visit www.maximumasp.com/max for a FREE 30 day trial. Hurry offer ends soon.
Climb aboard the MaxV platform and take advantage of High Availability, Intelligent Monitoring, Recurrent Backups, and Scalability – with no hassle or hidden fees.
As a managed hosting partner focused solely on Microsoft technologies since 2000, MaximumASP is uniquely qualified to provide the superior support that our business is built on. Unparalleled expertise with Microsoft technologies lead to working directly with Microsoft as first to offer IIS 7 and SQL 2008 betas in a hosted environment; partnering in the Go Live Program for Hyper-V; and product co-launches built on WS 2008 with Hyper-V technology.
|
Dynamic PDF
ceTE software specializes in components for dynamic PDF generation and manipulation. The DynamicPDF™ product line allows you to dynamically generate PDF documents, merge PDF documents and new content to existing PDF documents from within your applications.
|
Nevron Chart for .NET 2010.1 Now Available
The leading .NET charting control now features PDF, Flash and Silverlight export, visualization of large datasets and more. Deliver true charting functionality to your BI, Scorecard, Presentation or Scientific apps. Download evaluation now.
|
ASP.NET 4 Hosting
Get 2 Months Free of ASP.NET Hosting for Only $4.95/month! Receive FREE MS SQL and MySQL Databases Including ASP.NET 4/3.5, MVC 3.0, Silverlight 4, Windows 2008/IIS 7.0 Plus FREE IIS 7 Modules. Host UNLIMITED ASP.NET Web Sites – Click Here!
|
|
|
|
|
|
|
|
|
|
|
|
|