转自:https://blog.csdn.net/xl19900502/article/details/51445990
DWORD dwSize = GetFileVersionInfoSize(strPath, NULL);
UINT nSize = dwSize * sizeof(TCHAR);
LPVOID pBlock = new TCHAR[nSize];
memset(pBlock, 0, nSize);
GetFileVersionInfo(strPath, 0, dwSize, pBlock);
char* pVerValue = NULL;
nSize = 0;
VerQueryValue(pBlock, _T("\\VarFileInfo\\Translation"),
(LPVOID*)&pVerValue, &nSize);
CString strSubBlock, strTranslation, strTemp;
strTemp.Format(_T("000%x"), *((unsigned short int *)pVerValue));
strTranslation = strTemp.Right(4);
strTemp.Format(_T("000%x"), *((unsigned short int *)&pVerValue[2]));
strTranslation += strTemp.Right(4);
//080404b0为中文,040904E4为英文
//文件描述
strSubBlock.Format(_T("\\StringFileInfo\\%s\\FileDescription"), strTranslation);
VerQueryValue(pBlock, strSubBlock.GetBufferSetLength(256), (LPVOID*)&pVerValue, &nSize);
strSubBlock.ReleaseBuffer();
strTemp.Format(_T("文件描述: %s"), pVerValue);
//内部名称
strSubBlock.Format(_T("\\StringFileInfo\\%s\\InternalName"), strTranslation);
VerQueryValue(pBlock, strSubBlock.GetBufferSetLength(256), (LPVOID*)&pVerValue, &nSize);
strSubBlock.ReleaseBuffer();
strTemp.Format(_T("文件描述: %s"), pVerValue);
//合法版权
strSubBlock.Format(_T("\\StringFileInfo\\%s\\LegalTradeMarks"), strTranslation);
VerQueryValue(pBlock, strSubBlock.GetBufferSetLength(256), (LPVOID*)&pVerValue, &nSize);
strSubBlock.ReleaseBuffer();
strTemp.Format(_T("合法版权: %s"), pVerValue);
//原始文件名
strSubBlock.Format(_T("\\StringFileInfo\\%s\\OriginalFileName"), strTranslation);
VerQueryValue(pBlock, strSubBlock.GetBufferSetLength(256), (LPVOID*)&pVerValue, &nSize);
strSubBlock.ReleaseBuffer();
strTemp.Format(_T("原始文件名: %s"), pVerValue);
//产品名称
strSubBlock.Format(_T("\\StringFileInfo\\%s\\ProductName"), strTranslation);
VerQueryValue(pBlock, strSubBlock.GetBufferSetLength(256), (LPVOID*)&pVerValue, &nSize);
strSubBlock.ReleaseBuffer();
strTemp.Format(_T("产品名称: %s"), pVerValue);
//产品版本
strSubBlock.Format(_T("\\StringFileInfo\\%s\\ProductVersion"), strTranslation);
VerQueryValue(pBlock, strSubBlock.GetBufferSetLength(256), (LPVOID*)&pVerValue, &nSize);
strSubBlock.ReleaseBuffer();
strTemp.Format(_T("产品版本: %s"), pVerValue);
加上依赖,否则会报链接错误(GetFileVersionInfoSize)