OLD | NEW |
(Empty) | |
| 1 //------------------------------------------------------------------------------
------------------- |
| 2 // <copyright file="fileutil.cpp" company="Outercurve Foundation"> |
| 3 // Copyright (c) 2004, Outercurve Foundation. |
| 4 // This software is released under Microsoft Reciprocal License (MS-RL). |
| 5 // The license and further copyright text can be found in the file |
| 6 // LICENSE.TXT at the root directory of the distribution. |
| 7 // </copyright> |
| 8 // |
| 9 // <summary> |
| 10 // File helper functions. |
| 11 // </summary> |
| 12 //------------------------------------------------------------------------------
------------------- |
| 13 |
| 14 #include "../precomp.h" |
| 15 |
| 16 /******************************************************************* |
| 17 FileVersion |
| 18 |
| 19 ********************************************************************/ |
| 20 extern "C" HRESULT DAPI FileVersion( |
| 21 __in LPCWSTR wzFilename, |
| 22 __out DWORD *pdwVerMajor, |
| 23 __out DWORD* pdwVerMinor |
| 24 ) |
| 25 { |
| 26 HRESULT hr = S_OK; |
| 27 |
| 28 DWORD dwHandle = 0; |
| 29 UINT cbVerBuffer = 0; |
| 30 LPVOID pVerBuffer = NULL; |
| 31 VS_FIXEDFILEINFO* pvsFileInfo = NULL; |
| 32 UINT cbFileInfo = 0; |
| 33 |
| 34 if (0 == (cbVerBuffer = ::GetFileVersionInfoSizeW(wzFilename, &dwHandle))) |
| 35 { |
| 36 ExitOnLastErrorDebugTrace1(hr, "failed to get version info for file: %ls
", wzFilename); |
| 37 } |
| 38 |
| 39 pVerBuffer = ::GlobalAlloc(GMEM_FIXED, cbVerBuffer); |
| 40 ExitOnNullDebugTrace1(pVerBuffer, hr, E_OUTOFMEMORY, "failed to allocate ver
sion info for file: %ls", wzFilename); |
| 41 |
| 42 if (!::GetFileVersionInfoW(wzFilename, dwHandle, cbVerBuffer, pVerBuffer)) |
| 43 { |
| 44 ExitOnLastErrorDebugTrace1(hr, "failed to get version info for file: %ls
", wzFilename); |
| 45 } |
| 46 |
| 47 if (!::VerQueryValueW(pVerBuffer, L"\\", (void**)&pvsFileInfo, &cbFileInfo)) |
| 48 { |
| 49 ExitOnLastErrorDebugTrace1(hr, "failed to get version value for file: %l
s", wzFilename); |
| 50 } |
| 51 |
| 52 *pdwVerMajor = pvsFileInfo->dwFileVersionMS; |
| 53 *pdwVerMinor = pvsFileInfo->dwFileVersionLS; |
| 54 |
| 55 LExit: |
| 56 if (pVerBuffer) |
| 57 { |
| 58 ::GlobalFree(pVerBuffer); |
| 59 } |
| 60 return hr; |
| 61 } |
OLD | NEW |