ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • GetFileVersionInfo : 파일 버전 확인하는 방법
    Programming/WINAPI 2008. 2. 6. 14:26

    GetFileVersionInfo Function

    특정파일의 버전정보를 확인할때 GetFileVersionInfo 함수를 사용합니다.

    BOOL GetFileVersionInfo(         
        LPTSTR lptstrFilename,
        DWORD dwHandle,
        DWORD dwLen,
        LPVOID lpData
    );


    Parameters

    lptstrFilename

    버전을 확인할 파일명(전체경로포함).
    만약 전체경로가 포함되지 않은 파일명인 경우 LoadLibrary함수에서 설명된 경로에서 파일을 검색합니다.
    Windows 95/98/Me: 해당 OS에서는 파일명이 126자보다 작아야 합니다.

    dwHandle

    이 인자는 무시됩니다. ( 그냥 0 을 주시면 됩니다. )

    dwLen

    GetFileVersionInfoSize함수로 얻은 값(size)을 주시면 됩니다.
    이 값은 또한 lpData 버퍼의 크기가 됩니다.

    lpData

    파일 버전 정보를 반환받을 버퍼
    lpData로 들어온 데이터는 VerQueryValue 함수를 통해 최종적으로 파일의 버전정보를 확인할 수 있습니다.


    Return Value

    성공시, 0 이 아닌값을 리턴하고
    실패시, 0 을 리턴합니다.
    자세한 오류정보는 GetLastError 함수를 통해 확인 할 수 있습니다.


    Remarks

    Windows NT 3.51 and earlier: The version information functions do not work with 16-bit Windows file images.
    Windows 95/98/Me, Windows NT 4.0 and Windows 2000: These functions work on both 16- and 32-bit file images.
    Windows XP: These functions work on 16-, 32-, and 64-bit file images.
    Windows 95/98/Me: GetFileVersionInfoW is supported by the Microsoft Layer for Unicode. To use this version, you must add certain files to your application, as outlined in Microsoft Layer for Unicode on Windows 95/98/Me Systems.

    Function Information

    Minimum DLL Version version.dll
    Header Declared in Winver.h, include Windows.h
    Import library Version.lib
    Minimum operating systems Windows 95, Windows NT 3.1
    Unicode Implemented as ANSI and Unicode versions. 
    example


    #include <Windows.h>
    #pragma comment(lib,"version.lib")

    void main()
    {
         // 버전정보를 담을 버퍼
         char* buffer = NULL;
         // 버전을 확인할 파일
         char* name = "c:\\TestFolder\\test.exe";

         DWORD infoSize = 0;

         // 파일로부터 버전정보데이터의 크기가 얼마인지를 구합니다.
         infoSize = GetFileVersionInfoSize(name, 0);
         if(infoSize==0) return;

         // 버퍼할당
         buffer = new char[infoSize];
         if(buffer)
         {
              // 버전정보데이터를 가져옵니다.
              if(GetFileVersionInfo(name,0,infoSize, buffer)!=0)
              {
                    VS_FIXEDFILEINFO* pFineInfo = NULL;
                    UINT bufLen = 0;
                   // buffer로 부터 VS_FIXEDFILEINFO 정보를 가져옵니다.
                   if(VerQueryValue(buffer,"\\",(LPVOID*)&pFineInfo, &bufLen) !=0)
                   {    
                        WORD majorVer, minorVer, buildNum, revisionNum;
                        majorVer = HIWORD(pFineInfo->dwFileVersionMS);
                        minorVer = LOWORD(pFineInfo->dwFileVersionMS);
                        buildNum = HIWORD(pFineInfo->dwFileVersionLS);
                        revisionNum = LOWORD(pFineInfo->dwFileVersionLS);

                        // 파일버전 출력
                        printf("version : %d,%d,%d,%d\n",majorVer, minorVer, buildNum, revisionNum);
                    }
               }
              delete[] buffer;
          }
    }

    결과 : version : 1,0,0,1




    [문제해결/프로그램] - VersionChanger : 파일 버전 변경 프로그램
Designed by Tistory.