栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

如何从Visual C ++中的版本资源中读取

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

如何从Visual C ++中的版本资源中读取

这是我原始答案的编辑版本。

bool GetProductAndVersion(CStringA & strProductName, CStringA & strProductVersion){    // get the filename of the executable containing the version resource    TCHAR szFilename[MAX_PATH + 1] = {0};    if (GetModuleFileName(NULL, szFilename, MAX_PATH) == 0)    {        TRACE("GetModuleFileName failed with error %dn", GetLastError());        return false;    }    // allocate a block of memory for the version info    DWORD dummy;    DWORD dwSize = GetFileVersionInfoSize(szFilename, &dummy);    if (dwSize == 0)    {        TRACE("GetFileVersionInfoSize failed with error %dn", GetLastError());        return false;    }    std::vector<BYTE> data(dwSize);    // load the version info    if (!GetFileVersionInfo(szFilename, NULL, dwSize, &data[0]))    {        TRACE("GetFileVersionInfo failed with error %dn", GetLastError());        return false;    }    // get the name and version strings    LPVOID pvProductName = NULL;    unsigned int iProductNameLen = 0;    LPVOID pvProductVersion = NULL;    unsigned int iProductVersionLen = 0;    // replace "040904e4" with the language ID of your resources    if (!VerQueryValue(&data[0], _T("\StringFileInfo\040904e4\ProductName"), &pvProductName, &iProductNameLen) ||        !VerQueryValue(&data[0], _T("\StringFileInfo\040904e4\ProductVersion"), &pvProductVersion, &iProductVersionLen))    {        TRACE("Can't obtain ProductName and ProductVersion from resourcesn");        return false;    }    strProductName.SetString((LPCSTR)pvProductName, iProductNameLen);    strProductVersion.SetString((LPCSTR)pvProductVersion, iProductVersionLen);    return true;}


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/368203.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号