获取程序本身的版本号

Hello,guys!

During your programing , you could meet how to get your application's version sometimes,now I will tell you how to get the application's version from the VS_VERSION_INFO resource.

First ,you should make a project named GetVersion from MFC Appwizard(exe) depends on dialog!

Next, we create a button control  named IDC_BTN_GETVERSION, it uses to get the application function.In this button, we add the function named GetApplicationVersion(), it uses to get the application's version!

Before Add the function , we should add a library named Version.lib, code just like:

#pragma comment(lib,"Version.lib")

Now , we Add the function named GetApplicationVersion(), and no return value,just void prefix.

This function's code ,as follows :

 TCHAR szFullPath[MAX_PATH];
 DWORD dwVerInfoSize = 0;
 DWORD dwVerHnd;
 VS_FIXEDFILEINFO * pFileInfo;

 GetModuleFileName(NULL, szFullPath, sizeof(szFullPath));
    dwVerInfoSize = GetFileVersionInfoSize(szFullPath, &dwVerHnd);
    if (dwVerInfoSize)
    {
        // If we were able to get the information, process it:
        HANDLE  hMem;
        LPVOID  lpvMem;
  unsigned int uInfoSize = 0;
  
        hMem = GlobalAlloc(GMEM_MOVEABLE, dwVerInfoSize);
        lpvMem = GlobalLock(hMem);
        GetFileVersionInfo(szFullPath, dwVerHnd, dwVerInfoSize, lpvMem);

  ::VerQueryValue(lpvMem, (LPTSTR)_T("//"), (void**)&pFileInfo, &uInfoSize);

  WORD m_nProdVersion[4];
  
  // Product version from the FILEVERSION of the version info resource 
  m_nProdVersion[0] = HIWORD(pFileInfo->dwProductVersionMS); 
  m_nProdVersion[1] = LOWORD(pFileInfo->dwProductVersionMS);
  m_nProdVersion[2] = HIWORD(pFileInfo->dwProductVersionLS);
  m_nProdVersion[3] = LOWORD(pFileInfo->dwProductVersionLS); 

  CString strVersion ;
  strVersion.Format(_T("The file's version : %d.%d.%d.%d"),m_nProdVersion[0],
                  m_nProdVersion[1],m_nProdVersion[2],m_nProdVersion[3]);
  
  GlobalUnlock(hMem);
        GlobalFree(hMem);

  AfxMessageBox(strVersion);

}

It's very easy,do not you think ?

compile:

VC6.0 + VSP6 + WINXP!

 

  • 0
    点赞
  • 0
    收藏
  • 打赏
    打赏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
©️2022 CSDN 皮肤主题:大白 设计师:CSDN官方博客 返回首页
评论 2

打赏作者

taianmonkey

你的鼓励将是我创作的最大动力

¥2 ¥4 ¥6 ¥10 ¥20
输入1-500的整数
余额支付 (余额:-- )
扫码支付
扫码支付:¥2
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、C币套餐、付费专栏及课程。

余额充值