RT,我要在自己的代码中查看一个现有的DLL文件(路径已知)的properties的信息,应该如何获取信息?

解决方案 »

  1.   

    谢谢,楼上,问题已经解决了。
    代码如下:
    BOOL GetCurDLLInfo(CString & strCRandDes, const CString& strDLLAbbrev,const CString& strInfo)
    {
    //  strVersion = _T("Version: ");

    CString strTemp;
    TCHAR szFileName[MAX_PATH];
    memset(szFileName, 0, sizeof(szFileName)); ::GetModuleFileName(NULL, szFileName, sizeof(szFileName)/sizeof(TCHAR));

    if (!strDLLAbbrev.IsEmpty())
    {
    strTemp = szFileName;
    int pos = strTemp.ReverseFind(_T('\\'));
    strTemp = strTemp.Left(pos); CString strFindFile;
    strFindFile.Format(_T("%s\\MC??O%s.dll"), strTemp, strDLLAbbrev); CFileFind finder;
    BOOL bWorking = finder.FindFile(strFindFile);
    while (bWorking)
    {
    bWorking = finder.FindNextFile();
    if (!finder.IsDots())
    {
    if (!finder.IsDirectory())
    {
    strTemp = finder.GetFilePath();
    break;
    }
    }
    } _tcscpy(szFileName, strTemp);
    }

    LPDWORD lpdwHandle = NULL;
    DWORD dwLength = ::GetFileVersionInfoSize(szFileName, lpdwHandle);
    if (dwLength == 0)
    {
    AfxMessageBox(_T("Get file version failed"));
    return FALSE;
    }

    BYTE* byteData;
    byteData = new BYTE[dwLength];
    if (byteData == NULL)
    {
    AfxMessageBox(_T("Out of memory when get file version"));
    return FALSE;
    }
    memset(byteData, 0, dwLength); if (!::GetFileVersionInfo(szFileName, 0, dwLength, (LPVOID)byteData))
    {
    AfxMessageBox(_T("Get file version failed"));
    delete []byteData;
    return FALSE;
    } char*   pVerValue   =   NULL;   
    UINT   nSize   =   0;   
    VerQueryValue(byteData,TEXT("\\VarFileInfo\\Translation"),   
    (LPVOID*)&pVerValue,&nSize);    CString   strSubBlock,strTranslation;
    strTemp.Format("000%x",*((unsigned   short   int   *)pVerValue));   
    strTranslation   =   strTemp.Right(4);   
    strTemp.Format("000%x",*((unsigned   short   int   *)&pVerValue[2]));   
    strTranslation   +=   strTemp.Right(4);   
    //080404b0 Chinese 040904E4 English
    strSubBlock.Format("\\StringFileInfo\\%s\\%s",strTranslation,strInfo);   
    VerQueryValue(byteData,strSubBlock.GetBufferSetLength(256),(LPVOID*)&pVerValue,&nSize);   
    strSubBlock.ReleaseBuffer();
    strCRandDes.Format("%s",pVerValue);
    strCRandDes.TrimLeft(" ");
    strTemp.Format("%s",pVerValue);   
    AfxMessageBox(strTemp);   

    delete []byteData; return TRUE;
    }