VC++exe 또는 dll 버전 정보 가져오기

4277 단어
#include 
#include 
#pragma comment(lib,"version.lib")

CString GetFileVersion(CString strExePath)
{
    DWORD   dwVerInfoSize = 0;
    DWORD dwVerHnd = 0;
    char   *pBuf;
    CString   asVer;
    VS_FIXEDFILEINFO   *pVsInfo;
    unsigned   int   iFileInfoSize = sizeof(VS_FIXEDFILEINFO);
    dwVerInfoSize = GetFileVersionInfoSize(strExePath, NULL);//            

    if (dwVerInfoSize)
    {
        pBuf = new char[dwVerInfoSize];
        if (GetFileVersionInfo(strExePath, dwVerHnd, dwVerInfoSize, pBuf))//                 
        {
            struct LANGANDCODEPAGE
            {
                WORD    wLanguage;
                WORD    wCodePage;
            }*lpTranslate;

            if (VerQueryValue(pBuf, _T("\\VarFileInfo\\Translation"), (void**)&lpTranslate, &iFileInfoSize))
            {
                unsigned int version_len = 0;
                if (VerQueryValue(pBuf, _T("\\"), (void**)&pVsInfo, &version_len))
                {
                    asVer.Format(_T("%d.%d.%d.%d"), HIWORD(pVsInfo->dwFileVersionMS),
                        LOWORD(pVsInfo->dwFileVersionMS),
                        HIWORD(pVsInfo->dwFileVersionLS),
                        LOWORD(pVsInfo->dwFileVersionLS));
                }
            }
        }
        delete   pBuf;
    }
    return   asVer;
}

int main()
{
    //      
    TCHAR    szModulePath[MAX_PATH * 2];
    ::GetModuleFileName(NULL, szModulePath, _countof(szModulePath) - 2);
    PathRemoveFileSpec(szModulePath);
    CString strExe = szModulePath;

    strExe += L"\\My.dll";

    CString strver = GetFileVersion(strExe);

    return 0;
}

좋은 웹페이지 즐겨찾기