应用程序如何获取自己的版本号(文件的版本号)?

NetCode 2004-08-18 02:51:52
应用程序如何获取自己的版本号(文件的版本号)?
...全文
616 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
superinsect 2004-08-18
  • 打赏
  • 举报
回复
使用下面这个函数, msdn有详细的说明。

BOOL GetFileVersionInfo( LPTSTR lptstrFilename,
DWORD dwHandle,
DWORD dwLen,
LPVOID lpData
);


The GetFileVersionInfoSize function determines whether the operating system can retrieve version information for a specified file. If version information is available, GetFileVersionInfoSize returns the size, in bytes, of that information.

Syntax

DWORD GetFileVersionInfoSize( LPTSTR lptstrFilename,
LPDWORD lpdwHandle
);
Parameters

lptstrFilename
[in] Pointer to a null-terminated string that specifies the name of the file of interest. The function uses the search sequence specified by the LoadLibrary function.
Windows 95/98/Me: The short path form of the specified file name must be less than 126 characters.

lpdwHandle
[out] Pointer to a variable that the function sets to zero.
Return Value

If the function succeeds, the return value is the size, in bytes, of the file's version information.

huaboy408 2004-08-18
  • 打赏
  • 举报
回复
少粘一个}

^_^
huaboy408 2004-08-18
  • 打赏
  • 举报
回复
个例子就是查询任何可执行文件的版本信息
并且 C++builder 和 VC 都通用,只需要把 AnsiString 替换成 CString 就行了。
下面是完整例子:
CString IS_GetAppVersion(char* AppName)
{
CString AppVersion;
//AppVersion=IS_GetAppCreateTime(AppName);

DWORD RessourceVersionInfoSize;
DWORD JustAJunkVariabel;
char* VersionInfoPtr;
struct LANGANDCODEPAGE {
WORD wLanguage;
WORD wCodePage;
} *TranslationPtr;
char* InformationPtr;
UINT VersionInfoSize;
char VersionValue[255];

RessourceVersionInfoSize=GetFileVersionInfoSize(AppName,&JustAJunkVariabel);
if(0!=RessourceVersionInfoSize)
{
VersionInfoPtr=new char[RessourceVersionInfoSize];
if(GetFileVersionInfo(AppName,0,RessourceVersionInfoSize,VersionInfoPtr))
{
if(!VerQueryValue(
VersionInfoPtr,
TEXT("VarFileInfo\\Translation"),
(LPVOID*)&TranslationPtr,
&VersionInfoSize))
{
delete[] VersionInfoPtr;
return AppVersion;
}
}

// retrieve File Description
wsprintf(VersionValue,
TEXT("\\StringFileInfo\\%04x%04x\\FileVersion"),
TranslationPtr[0].wLanguage,
TranslationPtr[0].wCodePage);

if(!VerQueryValue(
VersionInfoPtr,
VersionValue,
(LPVOID*)&InformationPtr,
&VersionInfoSize))
{
delete[] VersionInfoPtr;
return AppVersion;
}
if(strlen(InformationPtr)>0) //Not Null
{
AppVersion=CString(InformationPtr);
}
delete[] VersionInfoPtr;
}
return AppVersion;
}

void CGetFileVersionDlg::OnButton1()
{
CString strVersion = IS_GetAppVersion("d:\\winnt\\winhlp32.exe");
AfxMessageBox(strVersion);
bohut 2004-08-18
  • 打赏
  • 举报
回复
http://blog.csdn.net/taianmonkey/archive/2004/06/29/29762.aspx
bohut 2004-08-18
  • 打赏
  • 举报
回复
http://community.csdn.net/Expert/topic/3216/3216415.xml?temp=.8265497

16,473

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC相关问题讨论
社区管理员
  • 基础类社区
  • Web++
  • encoderlee
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

        VC/MFC社区版块或许是CSDN最“古老”的版块了,记忆之中,与CSDN的年龄几乎差不多。随着时间的推移,MFC技术渐渐的偏离了开发主流,若干年之后的今天,当我们面对着微软的这个经典之笔,内心充满着敬意,那些曾经的记忆,可以说代表着二十年前曾经的辉煌……
        向经典致敬,或许是老一代程序员内心里面难以释怀的感受。互联网大行其道的今天,我们期待着MFC技术能够恢复其曾经的辉煌,或许这个期待会永远成为一种“梦想”,或许一切皆有可能……
        我们希望这个版块可以很好的适配Web时代,期待更好的互联网技术能够使得MFC技术框架得以重现活力,……

试试用AI创作助手写篇文章吧