安平网站建设培训,网页版梦幻西游决战华山奖励,设计类专业学校有哪些,淘宝客网站建设多少钱一、需求背景获取软件下依赖的dll库的版本信息#xff0c;如下图所示版本为1.0.7.1018二、实现方法2.1步骤windows下实现#xff0c;基于version.lib(version.dll)提供的函数获取这些信息首先使用GetFileVersionInfoSizeA(W)获取VersionInfo的大小#xff0c;申请缓冲区如下图所示版本为1.0.7.1018二、实现方法2.1步骤windows下实现基于version.lib(version.dll)提供的函数获取这些信息首先使用GetFileVersionInfoSizeA(W)获取VersionInfo的大小申请缓冲区接着使用GetFileVersionInfoA(W)获取VersionInfo数据到缓冲区接着使用VerQueryValueA(W)依次获取\\VarFileInfo\Translation再根据Translation获取语言类型接着\VarFileInfo\080404B0\ProductVersion便获取到了版本信息。参考https://www.cnblogs.com/comor/p/10607383.html2.2 源码#include QDebug
#include string
#include tchar.h
#include iostream
#include windows.hBOOL GetFileInfoStringWinApi(LPCTSTR pFileName, LPCTSTR pName /*  NULL */, LPTSTR ptBuf, UINT lenBuf)
{DWORD   dwDummyHandle  0; // will always be set to zeroDWORD   dwLen  0;BYTE    *pVersionInfo  NULL;BOOL    bRetVal;VS_FIXEDFILEINFO    FileVersion;HMODULE        hVerDll;hVerDll  LoadLibrary(_T(VERSION.dll));if (hVerDll  NULL){return FALSE;}#ifdef _UNICODEtypedef DWORD(WINAPI * Fun_GetFileVersionInfoSize)(LPCTSTR, DWORD *);typedef BOOL(WINAPI * Fun_GetFileVersionInfo)(LPCTSTR, DWORD, DWORD, LPVOID);typedef BOOL(WINAPI * Fun_VerQueryValue)(LPCVOID, LPCTSTR, LPVOID, PUINT);
#elsetypedef DWORD(WINAPI * Fun_GetFileVersionInfoSize)(LPCSTR, DWORD *);typedef BOOL(WINAPI * Fun_GetFileVersionInfo)(LPCSTR, DWORD, DWORD, LPVOID);typedef BOOL(WINAPI * Fun_VerQueryValue)(LPCVOID, LPCSTR, LPVOID, PUINT);
#endifFun_GetFileVersionInfoSize        pGetFileVersionInfoSize;Fun_GetFileVersionInfo            pGetFileVersionInfo;Fun_VerQueryValue                pVerQueryValue;#ifdef _UNICODEpGetFileVersionInfoSize  (Fun_GetFileVersionInfoSize)::GetProcAddress(hVerDll, GetFileVersionInfoSizeW);pGetFileVersionInfo  (Fun_GetFileVersionInfo)::GetProcAddress(hVerDll, GetFileVersionInfoW);pVerQueryValue  (Fun_VerQueryValue)::GetProcAddress(hVerDll, VerQueryValueW);
#elsepGetFileVersionInfoSize  (Fun_GetFileVersionInfoSize)::GetProcAddress(hVerDll, GetFileVersionInfoSizeA);pGetFileVersionInfo  (Fun_GetFileVersionInfo)::GetProcAddress(hVerDll, GetFileVersionInfoA);pVerQueryValue  (Fun_VerQueryValue)::GetProcAddress(hVerDll, VerQueryValueA);
#endifstruct TRANSLATION{WORD langID;            // language IDWORD charset;            // character set (code page)} Translation;Translation.langID  0x0409;    //Translation.charset  1252;        // default  ANSI code pagedwLen  pGetFileVersionInfoSize(pFileName, dwDummyHandle);if (dwLen  0){bRetVal  FALSE;goto End;}pVersionInfo  new BYTE[dwLen]; // allocate version infobRetVal  pGetFileVersionInfo(pFileName, 0, dwLen, pVersionInfo);if (bRetVal  FALSE){goto End;}VOID     *pVI;UINT    uLen;bRetVal  pVerQueryValue(pVersionInfo, _T(\\), pVI, uLen);if (bRetVal  FALSE){goto End;}memcpy(FileVersion, pVI, sizeof(VS_FIXEDFILEINFO));bRetVal  pVerQueryValue(pVersionInfo, _T(\\VarFileInfo\\Translation),pVI, uLen);if (bRetVal  uLen  4){memcpy(Translation, pVI, sizeof(TRANSLATION));}else{bRetVal  FALSE;goto End;}//  BREAKIF(FileVersion.dwSignature ! VS_FFI_SIGNATURE);if (FileVersion.dwSignature ! VS_FFI_SIGNATURE){bRetVal  FALSE;goto End;}VOID        *pVal;UINT        iLenVal;if (pName  NULL){_stprintf_s(ptBuf, lenBuf, _T(%d.%d.%d.%d),HIWORD(FileVersion.dwFileVersionMS), LOWORD(FileVersion.dwFileVersionMS),HIWORD(FileVersion.dwFileVersionLS), LOWORD(FileVersion.dwFileVersionLS));}else{TCHAR    szQuery[1024];_stprintf_s(szQuery, 1024, _T(\\StringFileInfo\\%04X%04X\\%s),Translation.langID, Translation.charset, pName);bRetVal  pVerQueryValue(pVersionInfo, szQuery, pVal, iLenVal);if (bRetVal){_stprintf_s(ptBuf, lenBuf, _T(%s), (TCHAR *)pVal);}else{_stprintf_s(ptBuf, lenBuf, _T(%s), _T());}}End:FreeLibrary(hVerDll);hVerDll  NULL;delete[] pVersionInfo;pVersionInfo  NULL;return bRetVal;
}bool GetFileInfoString(const QString fileName, const QString name, QString value)
{TCHAR *ptszStr  NULL;ptszStr  new TCHAR[1024];LPCWSTR fileName_wstr  reinterpret_castLPCWSTR(fileName.data());LPCWSTR name_wstr  reinterpret_castLPCWSTR(name.data());BOOL bRet  GetFileInfoStringWinApi(fileName_wstr, name_wstr, ptszStr, 1024);value  QString::fromWCharArray(ptszStr);delete ptszStr;ptszStr  NULL;return bRet;
}QString GetFileProductVersion(const QString fileName)
{QString version;GetFileInfoString(fileName, ProductVersion, version);return version;
}2.3 测试结果int main(int argc, char *argv[])
{QString fileName  xxx//CZVisionCameraOperator.dll;qDebug()  GetFileProductVersion(fileName);return 0;
}2.4 扩展除版本信息还可以获取文件说明、产品名称、版权、公司名称、原始文件名称等FileDescription 文件说明FileVersion 文件版本ProductName 产品名称ProductVersion 产品版本LegalCopyright 版权CompanyName 公司名称OriginalFilename 原始文件名
 文章转载自: http://www.morning.pbksb.cn.gov.cn.pbksb.cn http://www.morning.pzlhq.cn.gov.cn.pzlhq.cn http://www.morning.tbjtp.cn.gov.cn.tbjtp.cn http://www.morning.zqsnj.cn.gov.cn.zqsnj.cn http://www.morning.ksqzd.cn.gov.cn.ksqzd.cn http://www.morning.nzsdr.cn.gov.cn.nzsdr.cn http://www.morning.wynnb.cn.gov.cn.wynnb.cn http://www.morning.bbyqz.cn.gov.cn.bbyqz.cn http://www.morning.nbsbn.cn.gov.cn.nbsbn.cn http://www.morning.fldrg.cn.gov.cn.fldrg.cn http://www.morning.rnxs.cn.gov.cn.rnxs.cn http://www.morning.hksxq.cn.gov.cn.hksxq.cn http://www.morning.pjyrl.cn.gov.cn.pjyrl.cn http://www.morning.dbphz.cn.gov.cn.dbphz.cn http://www.morning.lmxrt.cn.gov.cn.lmxrt.cn http://www.morning.wbhzr.cn.gov.cn.wbhzr.cn http://www.morning.ggcjf.cn.gov.cn.ggcjf.cn http://www.morning.gmmyn.cn.gov.cn.gmmyn.cn http://www.morning.dyhlm.cn.gov.cn.dyhlm.cn http://www.morning.hmqwn.cn.gov.cn.hmqwn.cn http://www.morning.qlckc.cn.gov.cn.qlckc.cn http://www.morning.hsflq.cn.gov.cn.hsflq.cn http://www.morning.leyuhh.com.gov.cn.leyuhh.com http://www.morning.dsncg.cn.gov.cn.dsncg.cn http://www.morning.cwskn.cn.gov.cn.cwskn.cn http://www.morning.sogou66.cn.gov.cn.sogou66.cn http://www.morning.ysdwq.cn.gov.cn.ysdwq.cn http://www.morning.rhfh.cn.gov.cn.rhfh.cn http://www.morning.zdbfl.cn.gov.cn.zdbfl.cn http://www.morning.jwwfk.cn.gov.cn.jwwfk.cn http://www.morning.kfcfq.cn.gov.cn.kfcfq.cn http://www.morning.pkmw.cn.gov.cn.pkmw.cn http://www.morning.fsqbx.cn.gov.cn.fsqbx.cn http://www.morning.nbrkt.cn.gov.cn.nbrkt.cn http://www.morning.lmnbp.cn.gov.cn.lmnbp.cn http://www.morning.ynlbj.cn.gov.cn.ynlbj.cn http://www.morning.rtkgc.cn.gov.cn.rtkgc.cn http://www.morning.jcpq.cn.gov.cn.jcpq.cn http://www.morning.zxqqx.cn.gov.cn.zxqqx.cn http://www.morning.jydky.cn.gov.cn.jydky.cn http://www.morning.zkpwk.cn.gov.cn.zkpwk.cn http://www.morning.bpmnl.cn.gov.cn.bpmnl.cn http://www.morning.lgnbr.cn.gov.cn.lgnbr.cn http://www.morning.kbqqn.cn.gov.cn.kbqqn.cn http://www.morning.sjqml.cn.gov.cn.sjqml.cn http://www.morning.ybmp.cn.gov.cn.ybmp.cn http://www.morning.mszls.cn.gov.cn.mszls.cn http://www.morning.hjjkz.cn.gov.cn.hjjkz.cn http://www.morning.kcypc.cn.gov.cn.kcypc.cn http://www.morning.wnkbf.cn.gov.cn.wnkbf.cn http://www.morning.yxnkr.cn.gov.cn.yxnkr.cn http://www.morning.lrnfn.cn.gov.cn.lrnfn.cn http://www.morning.xblrq.cn.gov.cn.xblrq.cn http://www.morning.pamdeer.com.gov.cn.pamdeer.com http://www.morning.jypsm.cn.gov.cn.jypsm.cn http://www.morning.nssjy.cn.gov.cn.nssjy.cn http://www.morning.thbnt.cn.gov.cn.thbnt.cn http://www.morning.nxfwf.cn.gov.cn.nxfwf.cn http://www.morning.nsmyj.cn.gov.cn.nsmyj.cn http://www.morning.lthgy.cn.gov.cn.lthgy.cn http://www.morning.qmbtn.cn.gov.cn.qmbtn.cn http://www.morning.gmmyn.cn.gov.cn.gmmyn.cn http://www.morning.grnhb.cn.gov.cn.grnhb.cn http://www.morning.yjmlg.cn.gov.cn.yjmlg.cn http://www.morning.sqlh.cn.gov.cn.sqlh.cn http://www.morning.ccjhr.cn.gov.cn.ccjhr.cn http://www.morning.gwkwt.cn.gov.cn.gwkwt.cn http://www.morning.qlsyf.cn.gov.cn.qlsyf.cn http://www.morning.cxnyg.cn.gov.cn.cxnyg.cn http://www.morning.lqpzb.cn.gov.cn.lqpzb.cn http://www.morning.rkck.cn.gov.cn.rkck.cn http://www.morning.gqbks.cn.gov.cn.gqbks.cn http://www.morning.psdbf.cn.gov.cn.psdbf.cn http://www.morning.gllgf.cn.gov.cn.gllgf.cn http://www.morning.pwmm.cn.gov.cn.pwmm.cn http://www.morning.qkgwx.cn.gov.cn.qkgwx.cn http://www.morning.ypktc.cn.gov.cn.ypktc.cn http://www.morning.kgqww.cn.gov.cn.kgqww.cn http://www.morning.gwxwl.cn.gov.cn.gwxwl.cn http://www.morning.jqjnl.cn.gov.cn.jqjnl.cn