且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

将 MFC 中的大型项目从 Visual C++ 6.0 迁移到 Visual Studio 2005

更新时间:2021-10-24 01:01:52

我在 这篇文章.去年我将一个百万行的单体应用从 VC6 移植到 VC9,结果证明非常困难.VC6 因即使在问世时也不太符合标准而臭名昭著,随着标准在随后几年的发展,VC6 的合规性变得更糟.微软借此机会在 VC7 中很大程度上修复了这个问题,但这样做破坏了很多在 VC6 中编译的代码.

I adressed porting from VC6 to VC9 in this post. I ported a million-line monolithic app from VC6 to VC9 last year, and it proved to be extraordinarily difficult. VC6 was notorious for being not very Standards-compliant even when it came out, and as the Standard evolved in the following years, VC6's compliance just became worse. Microsoft took the opportunity to fix this problem in VC7 to a large degree, but in doing so broke a lot of code that compiled in VC6.

在某些情况下,代码出错是因为代码本身很糟糕,而 VC7 是一个更好的编译器,它不允许 VC6 提供的许多***.但在许多情况下,好代码"(从 VC6 的角度来看)由于一致性的提高而变成了非法代码.一个很简单的例子:

In some cases the code broke because the code itself was poor, and VC7 was a much better compiler that did not allow many liberties that VC6 did. But in many cases "good code" (from VC6's point of view) became illegal code because of the increased conformance. A very simple example:

for( int i = 0, cont = 1; cont; ++i )
{
  // count something up
}

cout << "The number is now " << i << endl;

就 VC6 而言,这段代码非常好,但根据标准,i 超出了 for 块末尾的范围.从 VC6 到 VC7(以及从 VC7 到 VC8 等),还有很多其他类似的例子.在继续之前,您应该仔细查看这些更改:

This code is perfectly fine as far as VC6 is concerned, but according to the Standard i falls out of scope at the end of the for block. There are many, many other examples of things like this that changed from VC6 to VC7 (and from VC7 to VC8 etc). You should review these changes carefully before you proceed:

除了更好的合规性之外,我们还有许多令人信服的理由转向 VC9.一是能够编译 64 位应用程序,因此我们最终决定移植整个应用程序.但你可能有其他选择.

We had many compelling reasons to move to VC9 beyond just better compliance. One was the ability to compile 64-bit apps, and so we eventually decided to port the entire app. But you may have alternatives.

如果编译器仅在代码的一部分中为您创建了障碍,您可能会考虑仅移植该部分,并创建一个在 VC9 中编译的层,以弥合 VB 8.0 和 VC6 应用程序之间的差距.这可能只是一个编组代理,它只是在您的主应用程序和第 3 方组件之间移动数据.

If the compiler is creating a roadblock for you in just one portion of the code, you might consider porting just that portion, and creating a layer compiled in VC9 that bridges the gap between VB 8.0 and your VC6 application. This could be little more than a marshalling proxy, that does nothing more than move data between your main application and the 3rd-party component.