为现有 C++ 建立 VersionInfo 存在困难; DLL项目

发布于 2024-11-25 01:19:15 字数 1876 浏览 9 评论 0原文

我有一个现有的 C++ DLL,它可以正确编译,但没有与之关联的版本信息,例如已编译库的“属性”中的“版本”选项卡。奇怪的是,它在 Visual Studio 中确实有一个 .rc 文件,该文件与该项目关联,并且似乎定义正确。但是,无论是使用该文件,还是将其替换为 将资源文件添加到VC6 dllDLL 中的版本资源不可见右键单击,或http://www.codeproject.com/ KB/DLL/XDllPt3.aspx,我仍然无法让它导出DLL信息。我无法发布该项目的大部分代码,因为它是内部的,但这是 .rc 文件的内容: //Microsoft Developer Studio 生成的资源脚本。 //

#include "afxres.h"

/////////////////////////////////////////////////////////////////////////////
// English (U.S.) resources

#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU)
#ifdef _WIN32
LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US
#pragma code_page(1252)
#endif //_WIN32

/////////////////////////////////////////////////////////////////////////////
//
// Version
//

VS_VERSION_INFO VERSIONINFO
 FILEVERSION 1,0,0,1
 PRODUCTVERSION 1,0,0,1
 FILEFLAGSMASK 0x3fL
#ifdef _DEBUG
 FILEFLAGS 0x1L
#else
 FILEFLAGS 0x0L
#endif
 FILEOS 0x4L
 FILETYPE 0x1L
 FILESUBTYPE 0x0L
BEGIN
    BLOCK "StringFileInfo"
    BEGIN
        BLOCK "040904B0"
        BEGIN
            VALUE "CompanyName", "\0"
            VALUE "FileDescription", "PTU DLL library\0"
            VALUE "FileVersion", "1, 0, 0, 1\0"
            VALUE "InternalName", "PTUDLL32\0"
            VALUE "LegalCopyright", "Copyright (C) 1999\0"
            VALUE "ProductName", "PTU DLL library\0"
            VALUE "ProductVersion", "1, 0, 0, 1\0"
        END
    END
    BLOCK "VarFileInfo"
    BEGIN
        VALUE "Translation", 0x409, 1200
    END
END


#endif    // English (U.S.) resources
/////////////////////////////////////////////////////////////////////////////    

I have an extant C++ DLL which compiles properly, but has no version information associated with it such was the Version tab in Properties for the compiled library. The odd things about it is that it does have a .rc file in Visual Studio which is associated with the project and which seems to be correctly defined. However, whether using that file, or replacing it with values from locations such as Adding resource file to VC6 dll, Version resource in DLL not visible with right-click, or http://www.codeproject.com/KB/DLL/XDllPt3.aspx, I still cannot get it to export the DLL info. I cannot post most of the code of the project, since it is internal, but this is the contents of the .rc file:
//Microsoft Developer Studio generated resource script.
//

#include "afxres.h"

/////////////////////////////////////////////////////////////////////////////
// English (U.S.) resources

#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU)
#ifdef _WIN32
LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US
#pragma code_page(1252)
#endif //_WIN32

/////////////////////////////////////////////////////////////////////////////
//
// Version
//

VS_VERSION_INFO VERSIONINFO
 FILEVERSION 1,0,0,1
 PRODUCTVERSION 1,0,0,1
 FILEFLAGSMASK 0x3fL
#ifdef _DEBUG
 FILEFLAGS 0x1L
#else
 FILEFLAGS 0x0L
#endif
 FILEOS 0x4L
 FILETYPE 0x1L
 FILESUBTYPE 0x0L
BEGIN
    BLOCK "StringFileInfo"
    BEGIN
        BLOCK "040904B0"
        BEGIN
            VALUE "CompanyName", "\0"
            VALUE "FileDescription", "PTU DLL library\0"
            VALUE "FileVersion", "1, 0, 0, 1\0"
            VALUE "InternalName", "PTUDLL32\0"
            VALUE "LegalCopyright", "Copyright (C) 1999\0"
            VALUE "ProductName", "PTU DLL library\0"
            VALUE "ProductVersion", "1, 0, 0, 1\0"
        END
    END
    BLOCK "VarFileInfo"
    BEGIN
        VALUE "Translation", 0x409, 1200
    END
END


#endif    // English (U.S.) resources
/////////////////////////////////////////////////////////////////////////////    

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

卖梦商人 2024-12-02 01:19:15

实际上我的问题是如何将版本信息放入其中。但事实上,问题本身就解决了。显然该项目附带的资源文件已损坏。创建一个新项目,将其附加到项目中,然后移动所提供的信息以使其发挥作用。谢谢。

Actually my question was on getting the version info into it. But as it is, the problem resolved itself. Apparently the resource file that came with the project had gotten corrupted. Creating a new one, attaching it to the project, and moving over the information served to make it work. Thank you.

哆兒滾 2024-12-02 01:19:15

要从文件中检索版本信息,您需要使用 GetFileVersionInfo()。在调用 GetFileVersionInfoSize() 检索版本信息之前,您应该采取额外的步骤来确定存储的版本信息的大小。

bool GetVersionInfo(const char *filename, int &major, int &minor)
{
    DWORD   verBufferSize;
    char    verBuffer[2048];

    //  Get the size of the version info block in the file
    verBufferSize = GetFileVersionInfoSize(filename, NULL);
    if(verBufferSize > 0 && verBufferSize <= sizeof(verBuffer))
    {
        //  get the version block from the file
        if(TRUE == GetFileVersionInfo(filename, NULL, verBufferSize, verBuffer))
        {
            UINT length;
            VS_FIXEDFILEINFO *verInfo = NULL;

            //  Query the value
            if(TRUE == VerQueryValue(verBuffer, "\\", reinterpret_cast<LPVOID*>(&verInfo), &length))
            {
                //  Pull the version values. You can alternatively
                //  get the version of the file from dwFileVersionMS
                //  and dwFileVersionLS if necessary.
                major = verInfo->dwProductVersionMS;
                minor = verInfo->dwProductVersionLS;

                return true;
            }
        }
    }

    return false;
}

To retrieve the version information from a file you need to use GetFileVersionInfo(). You should take the additional step of determining the size of the version information stored before retrieving it with a call to GetFileVersionInfoSize().

bool GetVersionInfo(const char *filename, int &major, int &minor)
{
    DWORD   verBufferSize;
    char    verBuffer[2048];

    //  Get the size of the version info block in the file
    verBufferSize = GetFileVersionInfoSize(filename, NULL);
    if(verBufferSize > 0 && verBufferSize <= sizeof(verBuffer))
    {
        //  get the version block from the file
        if(TRUE == GetFileVersionInfo(filename, NULL, verBufferSize, verBuffer))
        {
            UINT length;
            VS_FIXEDFILEINFO *verInfo = NULL;

            //  Query the value
            if(TRUE == VerQueryValue(verBuffer, "\\", reinterpret_cast<LPVOID*>(&verInfo), &length))
            {
                //  Pull the version values. You can alternatively
                //  get the version of the file from dwFileVersionMS
                //  and dwFileVersionLS if necessary.
                major = verInfo->dwProductVersionMS;
                minor = verInfo->dwProductVersionLS;

                return true;
            }
        }
    }

    return false;
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文