从资源中提取版本信息

    技术2022-05-18  15

    #include <Winver.h>#pragma comment(lib,"Version.lib")

    typedef struct tagVERSION_DATA {    WORD wMajor;    WORD wMinor;    WORD wRevision;    WORD wBuild;} VERSION_DATA, *PVERSION_DATA;

    /*/brief GetLibraryVersion, 获取资源文件中的版本信息/param hModule, exe,DLL 句柄/return 返回*/VERSION_DATA GetLibraryVersion(HMODULE hModule){    VERSION_DATA Version;    TCHAR szFullPath[MAX_PATH];    DWORD dwVerInfoSize = 0;    DWORD dwVerHnd;    VS_FIXEDFILEINFO *pFileInfo = NULL;        GetModuleFileName(hModule, 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);                // Product version from the FILEVERSION of the version info resource             Version.wMajor    = HIWORD(pFileInfo->dwProductVersionMS);         Version.wMinor    = LOWORD(pFileInfo->dwProductVersionMS);        Version.wRevision = HIWORD(pFileInfo->dwProductVersionLS);        Version.wBuild      = LOWORD(pFileInfo->dwProductVersionLS);             GlobalUnlock(hMem);        GlobalFree(hMem);    }    return Version;}


    最新回复(0)