'DLLVERSIONINFO' 从VS2008将项目更新到VS2012后编译错误



我有一个非常旧的C++应用程序,多年来,在我之前,源代码已经迁移了很多次。它现在在VS2008下构建和编译。我决定迁移到VS2012,在这样做之后,我现在收到以下编译器错误:错误C2371:"DLLVERSIONINFO":重新定义;不同的基本类型

我没有更改任何一行代码。我只是简单地将项目从VS2008更新到VS2012。

在访问了MSDN并浏览了一点之后,我在_DLLVERSIONINFO结构的末尾注释掉了结构的最后一部分"DLLVERSIONINFO"。

现在项目编译并运行!!!

我的问题如下:1) 这是否意味着微软改变了这个结构在VS2012中的工作方式?2) 如果我把评论部分永远放在一边,我可能会遇到什么样的问题?

下面的源代码。

// 1998 Microsoft Systems Journal
//
// If this code works, it was written by Paul DiLascia.
// If not, I don't know who wrote it.
// http://www.microsoft.com/msj/0498/c0498.aspx
#ifndef __MODULEVER_H
#define __MODULEVER_H
// tell linker to link with version.lib for VerQueryValue, etc.
#pragma comment(linker, "/defaultlib:version.lib")
#ifndef DLLVERSIONINFO
// following is from shlwapi.h, in November 1997 release of the Windows SDK
typedef struct _DllVersionInfo
{
    DWORD cbSize;
    DWORD dwMajorVersion;                   // Major version
    DWORD dwMinorVersion;                   // Minor version
    DWORD dwBuildNumber;                    // Build number
    DWORD dwPlatformID;                     // DLLVER_PLATFORM_*
} /*DLLVERSIONINFO*/; // commented out this part
// Platform IDs for DLLVERSIONINFO
#define DLLVER_PLATFORM_WINDOWS         0x00000001      // Windows 95
#define DLLVER_PLATFORM_NT              0x00000002      // Windows NT
#endif // DLLVERSIONINFO
// value must pair with static LPCTSTR Keys[]  in method CString
//  CMainVersion::GetFile_VS_VERSION_INFO(...)
typedef  enum  {
    eCompanyName = 0,
    eFileDescription = 1,
    eFileVersion = 2,
    eInternalName = 3,
    eLegalCopyright = 4,
    eOriginalFilename = 5,
    eProductName = 6,
    eProductVersion = 7,
    eAllInfo = 8
} E_VS_VERSION_INFO;
class CModuleVersion : public VS_FIXEDFILEINFO 
{
protected:
 BYTE* m_pVersionInfo;  // all version info
 struct TRANSLATION {
    WORD langID;            // language ID
    WORD charset;           // character set (code page)
} m_translation;
public:
 CModuleVersion();
 virtual ~CModuleVersion();
 static CString GetModuleVersion();
 static CString GetModuleHistory();
 BOOL  GetFileVersionInfo(LPCTSTR modulename);
 CString    GetValue(LPCTSTR lpKeyName);
 static BOOL DllGetVersion(LPCTSTR modulename, DLLVERSIONINFO& dvi);
};
class CMainVersion 
{
public:
 CMainVersion();
 virtual ~CMainVersion();
static CString GetFileVersion(const CString & csModuleName);
static CString GetFile_VS_VERSION_INFO(const CString & csModuleName,
E_VS_VERSION_INFO eInfo);
static CString GetFileAndDllVersion(const CString & csModuleName);
static CString GetAllVersions();
};
#endif

显然,微软在VS2008和VS2012之间的某个时候添加了他们自己的DLLVERSIONINFO声明(在shlwapi.h中)。您不应该再手动声明它,只需使用#include <shlwapi.h>即可。

无论哪种方式,#ifndef DLLVERSIONINFO都不会起作用,因为DLLVERSIONINFO不是使用#define语句声明的。如果您想根据编译器版本有条件地定义DLLVERSIONINFO,请使用_MSC_VER,例如:

#if _MSC_VER >= 1700 // 1700 == VS2012
#include <shlwapi.h>
#else
// following is from shlwapi.h, in November 1997 release of the Windows SDK
typedef struct _DllVersionInfo
{
    DWORD cbSize;
    DWORD dwMajorVersion;                   // Major version
    DWORD dwMinorVersion;                   // Minor version
    DWORD dwBuildNumber;                    // Build number
    DWORD dwPlatformID;                     // DLLVER_PLATFORM_*
} DLLVERSIONINFO;
// Platform IDs for DLLVERSIONINFO
#define DLLVER_PLATFORM_WINDOWS         0x00000001      // Windows 95
#define DLLVER_PLATFORM_NT              0x00000002      // Windows NT
#endif // _MSC_VER

最新更新