获取可执行文件版本号(装载)

来源:互联网 发布:小米盒子破解版软件 编辑:程序博客网 时间:2024/04/28 00:36

这个例子就是查询任何可执行文件的版本信息  
  并且   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);  
  }  

/*

 char AppName[MAX_PATH];
 GetModuleFileName(NULL, AppName, MAX_PATH);

 CString   AppVersion;  
 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 FALSE;  
   }  
  }  
  
  //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 FALSE;  
  }  
  if(strlen(InformationPtr)>0)   //Not   Null  
  {  
   AppVersion=CString(InformationPtr);  
  }  
  delete[] VersionInfoPtr;  
 }  
*/

原创粉丝点击