取得文件的版本信息,网上搜索一般都说使用:
GetFileVersionInfoSize
GetFileVersionInfo
VerQueryValue
系列函数。
我使用这几个函数确实可以取得一些VC制作的EXE文件的版本,
但是对于WIN系统自带文件(比如notepad.exe)却无法取得。
在调用GetFileVersionInfoSize时就会有错误1812(指定的映像文件不包含资源区域),但是直接右键notepad.exe,看文件属性,是可以看到版本信息的。
请问,这些版本信息怎么得到?

解决方案 »

  1.   

    必须是程序的版本信息作为资源的形式存在才可以使用这些函数.
    其它方式肯定是得不到的.
    notepad这样的程序很早就有了,
    它保存版本信息的方式肯定不是VC中的那种方式.
      

  2.   

    我这notepad可以的.  xp sp2
      

  3.   

    可以么?
    我的是Win2000 sp4
    不能得到。
      

  4.   

    CString IS_GetAppVersion(char* AppName)
    {
    CString AppVersion;
    //AppVersion=IS_GetAppCreateTime(AppName); DWORD RessourceVersionInfoSize;
    DWORD JustAJunkVariabel;
    char* VersionInfoPtr;
    struct LANGANDCODEPAGE {
      WORD wLanguage;
      WORD wCodePage;
    } *TranslationPtr;
    char* InformationPtr;
    UINT  VersionInfoSize;
    char  VersionValue[255];    RessourceVersionInfoSize=GetFileVersionInfoSize(AppName,&JustAJunkVariabel);
        if(0!=RessourceVersionInfoSize)
        {
            VersionInfoPtr=new char[RessourceVersionInfoSize];
                if(GetFileVersionInfo(AppName,0,RessourceVersionInfoSize,VersionInfoPtr))
                {
                 if(!VerQueryValue(
                     VersionInfoPtr,
                     TEXT("VarFileInfo\\Translation"),
                        (LPVOID*)&TranslationPtr,
                        &VersionInfoSize))
                        {
                delete[] VersionInfoPtr;
                            return AppVersion;
                        }
                }     // retrieve File Description
    wsprintf(VersionValue,
                 TEXT("\\StringFileInfo\\%04x%04x\\FileVersion"),
                TranslationPtr[0].wLanguage,
                 TranslationPtr[0].wCodePage);    if(!VerQueryValue(
                 VersionInfoPtr,
                    VersionValue,
                    (LPVOID*)&InformationPtr,
                    &VersionInfoSize))
                    {
                     delete[] VersionInfoPtr;
                        return AppVersion;
                    }
    if(strlen(InformationPtr)>0) //Not Null
                {
                 AppVersion=CString(InformationPtr);
                }
                delete[] VersionInfoPtr;
        }
        return AppVersion;
    }
    notepad.exe也可以得到
      

  5.   

    zhucde
    好象不行,和我原来的错误一样,在GetFileVersionInfoSize的地方就失败了。