我正在尝试从dll文件中获取版本,这是我的代码:
std::string getVersionNumber()
{
LPCTSTR pFilePath = L"C:\\File.dll";
boost::filesystem::path full_path( boost::filesystem::current_path() );
std::string dllFile = full_path.string() + "/File.dll";
DWORD dwDummy;
DWORD dwFVISize = GetFileVersionInfoSize( pFilePath, &dwDummy );
LPBYTE lpVersionInfo = new BYTE[dwFVISize];
UINT uLen;
VS_FIXEDFILEINFO *lpFfi;
GetFileVersionInfo( pFilePath , 0 , dwFVISize , lpVersionInfo );
VerQueryValue( lpVersionInfo , L"\\" , (LPVOID *)&lpFfi , &uLen );
DWORD dwFileVersionMS = lpFfi->dwFileVersionMS;
DWORD dwFileVersionLS = lpFfi->dwFileVersionLS;
delete [] lpVersionInfo;
std::ostringstream stringStream;
stringStream << HIWORD(dwFileVersionMS) << ".";
stringStream << LOWORD(dwFileVersionMS) << ".";
stringStream << HIWORD(dwFileVersionLS) << ".";
stringStream << LOWORD(dwFileVersionLS);
return (stringStream.str());
}
如果我尝试以GetFileVersionInfoSize
作为第一个参数调用GetFileVersionInfo
和pFilePath
,它会完美地编译并运行。
但是,如果我尝试使用dllFile
调用它们,它(当然)不会编译,并且任何以某种方式将dllFile
转换为LPCTSTR
的尝试都会给我带来垃圾unicode字符。
我有点失落,有什么想法?