vendredi 8 août 2014

Difficulté à établir VersionInfo pour projet de DLL C++ existant - Stack Overflow


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
/////////////////////////////////////////////////////////////////////////////



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



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.



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
/////////////////////////////////////////////////////////////////////////////


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


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.


0 commentaires:

Enregistrer un commentaire