wchar_t* GetVersionString(wchar_t* szFile) { DWORD dwLen, dwUseless; LPTSTR lpVI; wchar_t* name; UINT verMajor; dwLen = GetFileVersionInfoSizeEx(FILE_VER_GET_NEUTRAL,(LPWSTR)szFile, &dwUseless); if (dwLen==0) { return 0; }else{ int o = 0; } lpVI = (LPTSTR) GlobalAlloc(GPTR, dwLen); if (lpVI) { DWORD dwBufSize; VS_FIXEDFILEINFO* lpFFI; BOOL bRet = FALSE; WORD* langInfo; UINT cbLang; WCHAR tszVerStrName[128]; LPVOID lpt; UINT cbBufSize = 0; GetFileVersionInfo((LPTSTR)szFile, NULL, dwLen, lpVI); if (VerQueryValue(lpVI, L"\\",(LPVOID *) &lpFFI, (UINT *) &dwBufSize)) { //We now have the VS_FIXEDFILEINFO in lpFFI verMajor = HIWORD(lpFFI->dwFileVersionMS); } //First, to get string information, we need to get language information. VerQueryValue(lpVI, L"\\VarFileInfo\\Translation",(LPVOID*)&langInfo, &cbLang); //Prepare the label -- default lang is bytes 0 & 1 of langInfo wsprintf(tszVerStrName, L"\\StringFileInfo\\%04x%04x\\%s",langInfo[0], langInfo[1], L"Description"); //Get the string from the resource data if (VerQueryValue(lpVI, tszVerStrName, &lpt, (PUINT)cbBufSize)) name = ((LPTSTR)lpt); //*must* save this //Cleanup GlobalFree((HGLOBAL)lpVI); } return name; } |
FILE_VER_GET_NEUTRAL 0x002 Loads the version resource strings from the corresponding MUI file, if available, and loads the binary version information (VS_FIXEDFILEINFO) from the corresponding language-neutral file, if available. This flag must be combined with FILE_VER_GET_LOCALISED. |
dwLen = 1652 szFile = 0x004d1bb0 L"C:\\Users\\Admin\\Documents\\Visual Studio 2012\\Projects\\MFCApplication1\\Debug\\MFCApplication1.exe" now From GetFileVersionInfoExW(...): lpVI = 0x004d1dd8 L"̸4" // looks in editor more like a "Á" error = 0 cbLang = 4 langInfo[0] = 1031 langInfo[1] = 1200 tszVerStrName = 0x0037e3b0 L"\\StringFileInfo\\040704b0\\Description" error = 1813 //<<--- dont know why!? |
DWORD dwLen, dwUseless; LPTSTR lpVI; wchar_t* name; UINT verMajor; dwLen = GetFileVersionInfoSizeEx(FILE_VER_GET_NEUTRAL|FILE_VER_GET_LOCALISED,(LPWSTR)szFile, &dwUseless); if (dwLen==0) { return 0; }else{ int o = 0; } lpVI = (LPTSTR) GlobalAlloc(GPTR, dwLen); if (lpVI) { DWORD dwBufSize; VS_FIXEDFILEINFO* lpFFI; BOOL bRet = FALSE; WORD* langInfo; UINT cbLang; WCHAR tszVerStrName[128]; LPVOID lpt; UINT cbBufSize = 0; GetFileVersionInfoExW(FILE_VER_GET_NEUTRAL|FILE_VER_GET_LOCALISED,(LPWSTR)szFile, NULL, dwLen, lpVI); if (VerQueryValue(lpVI, L"\\",(LPVOID *) &lpFFI, (UINT *) &dwBufSize)) { //We now have the VS_FIXEDFILEINFO in lpFFI verMajor = HIWORD(lpFFI->dwFileVersionMS); } DWORD error = GetLastError(); //First, to get string information, we need to get language information. VerQueryValue(lpVI, L"\\VarFileInfo\\Translation",(LPVOID*)&langInfo, &cbLang); error = GetLastError(); //Prepare the label -- default lang is bytes 0 & 1 of langInfo wsprintf(tszVerStrName, L"\\StringFileInfo\\%04x%04x\\%s",langInfo[0], langInfo[1], L"Description"); //Get the string from the resource data if (VerQueryValue(lpVI, tszVerStrName, &lpt, (PUINT)cbBufSize)) name = ((LPTSTR)lpt); //*must* save this error = GetLastError(); //Cleanup GlobalFree((HGLOBAL)lpVI); } return name; |
VerQueryValue(lpVI, tszVerStrName, &lpt, (PUINT)cbBufSize) |
VerQueryValue(lpVI, tszVerStrName, &lpt, &cbBufSize)
When this method returns, contains a pointer to the size of the requested data pointed to by lplpBuffer: for version information values, the length in characters of the string stored at lplpBuffer; for translation array values, the size in bytes of the array stored at lplpBuffer; and for root block, the size in bytes of the structure. |