从std :: string转换为LPCTSTR

时间:2013-08-19 13:58:42

标签: c++ string

我正在尝试从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作为第一个参数调用GetFileVersionInfopFilePath,它会完美地编译并运行。 但是,如果我尝试使用dllFile调用它们,它(当然)不会编译,并且任何以某种方式将dllFile转换为LPCTSTR的尝试都会给我带来垃圾unicode字符。

我有点失落,有什么想法?

0 个答案:

没有答案