1

I'm trying to get the version from a dll file, here is my code:

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());
}

if I try calling GetFileVersionInfoSize and GetFileVersionInfo with pFilePath as the first parameter, it compiles and runs perfectly. However, if I try calling them with dllFile, it (of course) doesn't compile, and any attempt to somehow convert dllFile to LPCTSTR gives me rubbish unicode characters.

I'm kinda lost, any ideas?

Nicol Bolas
  • 449,505
  • 63
  • 781
  • 982
Idanis
  • 1,918
  • 6
  • 38
  • 69
  • If you had Googled it, you would have found your answer. I found the dupe by merely Googling the title of you question. – Tony The Lion Aug 19 '13 at 14:01
  • 3
    Stating that *"it doesn't compile"* without providing the exact compiler message is a cardinal sin, the punishment for which is typically nasal demons. – abelenky Aug 19 '13 at 14:14
  • I googled it in many various ways and came up with nothing that works. All it gives me is a conversion from string to LPCSTR while I need it to be LPCTSTR. And there compilation error I get is: 'GetFileVersionInfoSizeW' : cannot convert parameter 1 from 'std::string' to 'LPCWSTR'. – Idanis Aug 19 '13 at 14:17
  • 2
    You don't need it to be `LPCTSTR`, just say `DWORD dwFVISize = GetFileVersionInfoSizeA( dllPath.c_str(), &dwDummy );` – Ben Voigt Aug 19 '13 at 15:18
  • Or use `full_path.wstring()` (and change types to `std::string` as appropriate) – Ben Voigt Aug 19 '13 at 15:20

0 Answers0