我正在尝试从 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
and作为第一个参数,它会完美编译并运行GetFileVersionInfo
。pFilePath
但是,如果我尝试用 调用它们dllFile
,它(当然)不会编译,并且任何试图以某种方式转换dllFile
为的尝试LPCTSTR
都会给我带来垃圾 unicode 字符。
我有点迷路了,有什么想法吗?