vc 获取程序版本号,当前程序路径,文件修改时间 等

获取版本:

 

[cpp:nogutter]  view plain copy
  1. CString GetFileVersion(char*  FileName)  
  2. {     
  3.     int   iVerInfoSize;  
  4.     char   *pBuf;  
  5.     CString   asVer="";  
  6.     VS_FIXEDFILEINFO   *pVsInfo;  
  7.     unsigned   int   iFileInfoSize   =   sizeof(   VS_FIXEDFILEINFO   );  
  8.       
  9.       
  10.     iVerInfoSize   =   GetFileVersionInfoSize(FileName,NULL);   
  11.       
  12.     if(iVerInfoSize!= 0)  
  13.     {     
  14.         pBuf   =   new   char[iVerInfoSize];  
  15.         if(GetFileVersionInfo(FileName,0,   iVerInfoSize,   pBuf   )   )     
  16.         {     
  17.             if(VerQueryValue(pBuf,   "//",(void   **)&pVsInfo,&iFileInfoSize))     
  18.             {     
  19.                 asVer.Format("%d.%d.%d.%d",HIWORD(pVsInfo->dwFileVersionMS),LOWORD(pVsInfo->dwFileVersionMS),HIWORD(pVsInfo->dwFileVersionLS),LOWORD(pVsInfo->dwFileVersionLS));  
  20.             }     
  21.         }     
  22.         delete   pBuf;     
  23.     }     
  24.     return   asVer;     
  25. }    

 

获取路径:

[cpp:nogutter]  view plain copy
  1. CString GetCurrentAppDirectory()  
  2. {  
  3.     char szFile[MAX_PATH];  
  4.     char szPath[MAX_PATH];  
  5.     GetModuleFileName(NULL,szFile,MAX_PATH);  
  6.     size_t i;  
  7.     for(i=strlen(szFile)-1; i>0 && szFile[i]!='//'; i--);  
  8.     szFile[i]='/0';  
  9.     strcpy(szPath,szFile);   
  10.     return (szPath);  
  11. }  

 

获取修改时间:

[cpp:nogutter]  view plain copy
  1. CString GetModifyTime(CString appname)  
  2. {  
  3.     WIN32_FIND_DATA ffd ;  
  4.     HANDLE hFind = FindFirstFile(appname,&ffd);  
  5.     SYSTEMTIME stUTC, stLocal;  
  6.     FileTimeToSystemTime(&(ffd.ftLastWriteTime), &stUTC);  
  7.     SystemTimeToTzSpecificLocalTime(NULL, &stUTC, &stLocal);  
  8.     CString strTmp;  
  9.     strTmp.Format("%d-%d-%d,%d:%d", stLocal.wYear,stLocal.wMonth,stLocal.wDay,stLocal.wHour,stLocal.wMinute);  
  10.     //--      
  11.     return strTmp;  
  12. }  

 转帖:http://blog.csdn.net/lanmanck/article/details/3901590


==============================================================================================

上面那个有问题,下面这个成功:

CString CMFCVLCDlg::GetFileVer()
{
 char cPath[200],szVersionBuffer[200];
 DWORD dwHandle,InfoSize;
 CString strVersion;
 ::GetModuleFileName(NULL,cPath,sizeof(cPath)); //首先获得版本信息资源的长度
 InfoSize = GetFileVersionInfoSize(cPath,&dwHandle); //将版本信息资源读入缓冲区
 if(InfoSize==0) return _T("None VerSion Supprot");
 char *InfoBuf = new char[InfoSize];
 GetFileVersionInfo(cPath,0,InfoSize,InfoBuf); //获得生成文件使用的代码页及文件版本
 unsigned int  cbTranslate = 0;
 struct LANGANDCODEPAGE {
  WORD wLanguage;
  WORD wCodePage;
 } *lpTranslate;
 VerQueryValue(InfoBuf, TEXT("\\VarFileInfo\\Translation"),(LPVOID*)&lpTranslate,&cbTranslate);
 // Read the file description for each language and code page.
 for( int i=0; i < (cbTranslate/sizeof(struct LANGANDCODEPAGE)); i++ )
 {
  char  SubBlock[200];
  wsprintf( SubBlock,
            TEXT("\\StringFileInfo\\%04x%04x\\FileVersion"),
            lpTranslate[i].wLanguage,
            lpTranslate[i].wCodePage);
  void *lpBuffer=NULL;
  unsigned int dwBytes=0;
  VerQueryValue(InfoBuf,
   SubBlock,
   &lpBuffer,
   &dwBytes);
  CString strTemp=(char *)lpBuffer;
  strVersion+=strTemp;
  
 }
 return strVersion;
}

转帖:http://www.cnblogs.com/wxlzhizu/archive/2009/12/09/1620009.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值