来获取工程exe自身的文件版本号的一个函数[by ccrun]

这是我自己写的一个小工程里的函数,用来获取工程exe自身的文件版本号:


[color=#0000D0]void[/color]   [color=#0000D0]__fastcall[/color]   MyGetAppVersion([color=#0000D0]LPSTR[/color]   lpFileVer)   
  {   
          [color=#0000D0]DWORD[/color]   dwHandle;   
          [color=#0000D0]UINT[/color]   unCurLen;   
    
          String   strFileName   =   Application->ExeName;   
          [color=#0000D0]DWORD[/color]   dwVerLen   =   [b][color=#000080]GetFileVersionInfoSize[/color][/b](strFileName.c_str(),   &dwHandle);   
          [color=#FF0000]strcpy[/color](lpFileVer,   [color=#808080]””[/color]);   
          [color=#0000D0]if[/color](dwVerLen)   
          {   
                  [color=#0000D0]LPSTR[/color]   lpData   =   [color=#0000D0]new[/color]   [color=#0000D0]char[/color][dwVerLen];   
                  [color=#0000D0]if[/color]([b][color=#000080]GetFileVersionInfo[/color][/b](strFileName.c_str(),   0,   dwVerLen,   lpData))   
                  {   
                          PVSFixedFileInfo   pvsFixFileInfo;   
                          [b][color=#000080]VerQueryValue[/color][/b](lpData,   [color=#808080]”\\”[/color],   ([color=#0000D0]void[/color]   **)&pvsFixFileInfo,   &unCurLen);   
                          [color=#0000D0]DWORD[/color]   dwFileType   =   pvsFixFileInfo->dwFileType;   
                          [color=#0000D0]if[/color]((dwFileType   ==   VFT_APP)   ||   (dwFileType   ==   VFT_DLL)   
                                          ||   (dwFileType   ==   VFT_VXD)   ||   (dwFileType   ==   VFT_STATIC_LIB))   
                          {   
                                  [color=#0000D0]PDWORD[/color]   pdwBuffer;   
                                  [color=#0000D0]UINT[/color]   unVerLen;   
                                  String   strLanguageCode;   
                                  [color=#008000]// 获取文件语言 [/color]
                                  [color=#0000D0]if[/color]([b][color=#000080]VerQueryValue[/color][/b](lpData,   TEXT([color=#808080]”\\VarFileInfo\\Translation”[/color]),   
                                                  ([color=#0000D0]void[/color]   **)&pdwBuffer,   &unVerLen))   
                                  {   
                                          [color=#0000D0]WORD[/color]   wLangID   =   [color=#b000b0]LOWORD[/color](([color=#0000D0]DWORD[/color])(*pdwBuffer));   
                                          [color=#0000D0]WORD[/color]   wLangSubID   =   [color=#b000b0]HIWORD[/color](([color=#0000D0]DWORD[/color])(*pdwBuffer));   
                                          strLanguageCode   =   String(IntToHex(wLangID,   4))   +   
                                                          String(IntToHex(wLangSubID,   4));   
                                  }   
                                  [color=#0000D0]PCHAR[/color]   pcBuf;   
                                  String   strTemp   =   [color=#808080]”\\StringFileInfo\\”[/color]   +   strLanguageCode   +   
                                          String([color=#808080]”\\FileVersion”[/color]);   
                                  [color=#0000D0]if[/color]([b][color=#000080]VerQueryValue[/color][/b](lpData,   strTemp.c_str(),   ([color=#0000D0]void[/color]   **)&pcBuf,   &unVerLen))   
                                          [color=#FF0000]strcpy[/color](lpFileVer,   pcBuf);   
                          }   
                  }   
                  [color=#0000D0]delete[/color][]   lpData;   
          }   
  }   
  [color=#008000]// 使用举例 [/color]
  [color=#0000D0]char[/color]   szBuf[64];   
  MyGetAppVersion(szBuf);   
  Label1->Caption   =   String([color=#808080]”版本: “[/color])   +   String(szBuf);
本代码由xTiNt自动着色 http://kbadboy.yeah.net

博主友情提示:

如在您的评论中需要提及如QQ号、微信号、电子邮件地址或其他隐私敏感信息,欢迎通过>>博主专用加密工具v2<<加密后发布,原文只有博主可以看到。