从2003年到2005年的转变太难了 [英] Conversion from 2003 to 2005 just too hard

查看:103
本文介绍了从2003年到2005年的转变太难了的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我整个上午都在尝试将我的2003项目(托管)转换为2005

(/ clr,因为我有托管和非托管代码)。我猜我有几万行代码需要改变。很多人将''__gc''

转换为''ref'',将''*'转换为''''',将''new''转换为''gcnew'' 。当然这个

不能用毯子替换来完成,因为我的代码既有托管又有
非托管段。因此,我必须一个接一个地做。此外,事情还缺少
。就像Form不再具有Bounds属性一样(或者至少如果我使用它b $ b尝试使用它我会得到''它不存在''错误,这是一行

在2003年编译得很好)。我不能拥有私人虚拟功能甚至

虽然他们在2003年没事(好吧,我明白为什么他们必须得到保护)。

简而言之,它有点恼火,不得不处理升级,

甚至不能远程向后兼容(甚至没有旧的语法切换

on)...


但是,即使在愿意做所有这些改变之后,我现在认为我应该停止进入Graphics类。


DrawPolygon()之类的图形方法显然不再编译。

仅给出的版本是使用旧语法格式的所需

__gc Points []数组。这个函数的无/ clr兼容重载给出了

(至少不在DrawPolygon的前瞻弹出窗口中)。那么

现在如何使用Graphics类绘制一个Polygon?


它看起来越来越多,如果你在2003年开始应该

(不幸的是)留在2003年。在2005年开始一个项目可能会很好,但转换是非常困难的,并且容易出现大量错误。甚至我在旧版语法2005版本中所做的

转换现在返回了它在2003年没有的

异常错误....:(


为什么MS没有写一个转换工具?当然它可能无法做到b / b
所有东西,但它可以做最明显的事情。喜欢:


(1)识别''__gc''的东西和''ref''它(注意这不作为毯子工作

编辑替换因为''__gc''也用于定义其他东西,比如数组)

(2)用''''替换相应的''''',用'''取代适当的''new''

''gcnew'',用新语法版本替换''__''单词(例如,

''__ delegate''带''委托'')

(3)保护适当的私有虚方法

(4)将抽象类更改为新语法

(5)重新定义数组新的''数组''语法

(6)识别不再有效的旧方法并加入新语法

(例如,用新语法替换MakePolygon()代码行,并执行此操作

会改变格式的所有这些方法)

(7)等


我看到编译器错误说的东西比如你做了X,用Y代替。

为什么编译器没有为你做出这些改动的选择?


我认为2005年与2003年有太大不同,称其为升级。如果一个人决定使用Managed C ++,那么它基本上与2003不兼容......


[== P ==]

I''ve been trying all morning to convert my 2003 project (managed) to 2005
(/clr since I have both managed and unmanaged code). I''m guessing I have
tens of thousands of lines of code to change. Did a lot of converting ''__gc''
to ''ref'', converting ''*'' to ''^'', converting ''new'' to ''gcnew''. Of course this
can''t be done with a blanket replace, as my code has both managed and
unmanaged segments. Thus I have to do them one-by-one. Also, things are
missing. Like Form no longer has a Bounds property anymore (or at least if I
try to use it I get an ''it doesn''t exist'' error, which is a line that
compiled just fine in 2003). I can''t have private virtual function even
though they were fine in 2003 (ok, i can see why they have to be protected).
In short, it''s kind of exasperating to have to deal with an upgrade that
isn''t even remotely backwards compatible (not even with old syntax switched
on)...

But, even after willing to do all of these changes, I now think I should
stop, having run into the Graphics class.

Graphics methods such as DrawPolygon() apparently no longer compile. The
only versions given are the ones using old syntax format for the required
__gc Points[] array. No /clr compatible overload of this function is given
(at least not in the look-ahead pop-up that comes up for DrawPolygon). So
how does one now draw a Polygon with the Graphics class now?

It''s looking more and more that if you started in 2003 one should
(unfortunately) stay in 2003. Starting a project in 2005 might be good, but
converting is extremely difficult and prone to lots of erros. And even the
conversion I did into an old syntax 2005 version now returns with an
exception error it didn''t have in 2003.... : (

Why didn''t MS write a conversion tool? Sure it probably couldn''t do
everything, but it could do the most obvious stuff. Like:

(1) identify ''__gc'' stuff and ''ref'' it (note this doesn''t work as a blanket
edit replace since ''__gc'' is also used to define other stuff, like arrays)
(2) replace appropriate ''*'' with ''^'', replace appropriate ''new'' with
''gcnew'', replace the ''__'' words with the new syntax versions (e.g.,
''__delegate'' with ''delegate'')
(3) make appropriate private virtual methods protected
(4) change abstract classes to the new syntax
(5) redefine arrays with the new ''array'' syntax
(6) identify old methods that no longer works and put in the new syntax
(e.g., replace MakePolygon() code lines with the new syntax, and do this
will all such methods which have changed format)
(7) etc.

I''ve seen compiler errors that say stuff like "you did X, use Y instead".
Why doesn''t the compiler give an option to make those changes FOR YOU?

I think 2005 is way too different from 2003 to call it an ''upgrade''. It''s
basically incompatible with 2003 if one decided to use Managed C++...

[==P==]

推荐答案

我理解你的痛苦,彼得 - 但是大约一年半的时间,这显然是在MC ++代码中投入时间了自从Herb Sutter在几个PDC之前谈到C ++ / CLI之后,就不会那么聪明了。

每次有人问过是否值得尝试使用Managed C ++(旧的

语法),我明确地告诉他们我的建议是等待2005年的b $ b.尽管这样做会这样做可能影响我书的销售额(以旧语法为目标)。


相关说明,这可能有助于我们中的一些人理解为什么很多当VB.NET出来时,VB6ers很生气,这不是升级,它是一个全新的

语言/语法等。


在另一个相关的说明中,我狂野我记得Stan Lippman说他是在使用新语法转换器的旧语法吗?但我不确定他是否已经完成了这项工作。


-

问候,

Nish [VC ++ MVP]

" Peter Oliphant" < PO ******* @ RoundTripInc.com>在消息中写道

新闻:e3 ************** @ TK2MSFTNGP14.phx.gbl ...
I understand your pain, Peter - but for about an year and a half, it was
pretty obvious that investing time in MC++ code would not be such a smart
thing to do, ever since Herb Sutter talked about C++/CLI a few PDCs ago.
Every time someone had asked if it was worthwhile to try Managed C++ (old
syntax), I had explicitly told them that my advice would be to wait for
2005. I did this in spite of the fact that this would probably affect the
sales of my book (which targetted the old syntax).

On a related note, this might help some of us understand why a lot of VB6ers
were pissed when VB.NET came out, it wasn''t an upgrade, it was a whole new
language/syntax etc.

On another related note, I vaguely remember Stan Lippman saying that he was
working on an old syntax to new syntax converter - but I am not sure that he
ever got around to finishing that.

--
Regards,
Nish [VC++ MVP]
"Peter Oliphant" <po*******@RoundTripInc.com> wrote in message
news:e3**************@TK2MSFTNGP14.phx.gbl...
我去过整个上午尝试将我的2003项目(托管)转换为2005
(/ clr,因为我有托管和非托管代码)。我猜我有成千上万行代码需要改变。做了很多转换''__gc''''ref'',将'''''转换为''^'',将''new''转换为''gcnew''。当然,这不能用毯子替换来完成,因为我的代码既有托管段也有非托管段。因此,我必须一个接一个地做。此外,
事情都缺失了。就像Form不再具有Bounds属性一样(或者至少如果我尝试使用它我会得到一个''它不存在''错误,这是一个编译得很好的
行在2003年)。我不能拥有私人虚拟
功能,即使他们在2003年没事(好吧,我明白他们为什么要受到保护)。简而言之,必须处理升级甚至无法远程向后兼容(甚至没有打开旧语法),这有点令人恼火......

但是,即使在愿意做所有这些改变之后,我现在认为我应该停止,进入Graphics类。

图形方法,如DrawPolygon()显然不再编译。仅给出的版本是使用旧语法格式的所需版本的
__gc Points []数组。没有/ clr兼容此函数的重载
(至少不在DrawPolygon的前瞻弹出窗口中)。那么现在如何使用Graphics类绘制Polygon呢?

它看起来越来越多,如果你在2003年开始,那么应该(不幸的是)留下来在2003年。在2005年开始一个项目可能会很好,但是转换非常困难并且容易出现很多错误。甚至我在旧版语法2005版本中所做的转换现在返回了它在2003年没有的
异常错误....:(

为什么没有MS写了一个转换工具吗?当然它可能无法做任何事情,但它可以做最明显的事情。比如:

(1)识别''__gc' 'stuff'''ref''它(请注意,这不是作为毯子编辑替换的,因为''__ gc''也用于定义其他东西,比如
数组)
(2)用''''替换相应的''*',用'gcnew''替换相应的''new'',用新的语法版本替换''__''字样(例如,''__ delegate''与''委托'')
(3)使适当的私有虚拟方法受到保护
(4)将抽象类改为新语法
( 5)用新的''数组''语法重新定义数组
(6)识别不再有效的旧方法添加新语法
(例如,用新语法替换MakePolygon()代码行,并执行此操作
将所有此类方法更改格式)
(7)等

我看到编译器错误说你做了X,用Y代替等。
为什么编译器没有为你做出这些改动的选择呢? br />
我认为2005年与2003年有太大的不同,称之为升级。如果决定使用Managed C ++,它基本上与2003不兼容...

[== P ==]
I''ve been trying all morning to convert my 2003 project (managed) to 2005
(/clr since I have both managed and unmanaged code). I''m guessing I have
tens of thousands of lines of code to change. Did a lot of converting
''__gc'' to ''ref'', converting ''*'' to ''^'', converting ''new'' to ''gcnew''. Of
course this can''t be done with a blanket replace, as my code has both
managed and unmanaged segments. Thus I have to do them one-by-one. Also,
things are missing. Like Form no longer has a Bounds property anymore (or
at least if I try to use it I get an ''it doesn''t exist'' error, which is a
line that compiled just fine in 2003). I can''t have private virtual
function even though they were fine in 2003 (ok, i can see why they have
to be protected). In short, it''s kind of exasperating to have to deal with
an upgrade that isn''t even remotely backwards compatible (not even with
old syntax switched on)...

But, even after willing to do all of these changes, I now think I should
stop, having run into the Graphics class.

Graphics methods such as DrawPolygon() apparently no longer compile. The
only versions given are the ones using old syntax format for the required
__gc Points[] array. No /clr compatible overload of this function is given
(at least not in the look-ahead pop-up that comes up for DrawPolygon). So
how does one now draw a Polygon with the Graphics class now?

It''s looking more and more that if you started in 2003 one should
(unfortunately) stay in 2003. Starting a project in 2005 might be good,
but converting is extremely difficult and prone to lots of erros. And even
the conversion I did into an old syntax 2005 version now returns with an
exception error it didn''t have in 2003.... : (

Why didn''t MS write a conversion tool? Sure it probably couldn''t do
everything, but it could do the most obvious stuff. Like:

(1) identify ''__gc'' stuff and ''ref'' it (note this doesn''t work as a
blanket edit replace since ''__gc'' is also used to define other stuff, like
arrays)
(2) replace appropriate ''*'' with ''^'', replace appropriate ''new'' with
''gcnew'', replace the ''__'' words with the new syntax versions (e.g.,
''__delegate'' with ''delegate'')
(3) make appropriate private virtual methods protected
(4) change abstract classes to the new syntax
(5) redefine arrays with the new ''array'' syntax
(6) identify old methods that no longer works and put in the new syntax
(e.g., replace MakePolygon() code lines with the new syntax, and do this
will all such methods which have changed format)
(7) etc.

I''ve seen compiler errors that say stuff like "you did X, use Y instead".
Why doesn''t the compiler give an option to make those changes FOR YOU?

I think 2005 is way too different from 2003 to call it an ''upgrade''. It''s
basically incompatible with 2003 if one decided to use Managed C++...

[==P==]



" Peter Oliphant" < PO ******* @ RoundTripInc.com>写在

新闻:e3 ************** @ TK2MSFTNGP14.phx.gbl:
"Peter Oliphant" <po*******@RoundTripInc.com> wrote in
news:e3**************@TK2MSFTNGP14.phx.gbl:
图形方法如DrawPolygon()显然不再编译。
给出的唯一版本是使用旧语法格式的
必需__gc Points []数组。没有/ clr兼容此功能的重载(至少不会出现在DrawPolygon中出现的前瞻弹出窗口)。那么现在如何使用Graphics
类绘制Polygon?
Graphics methods such as DrawPolygon() apparently no longer compile.
The only versions given are the ones using old syntax format for the
required __gc Points[] array. No /clr compatible overload of this
function is given (at least not in the look-ahead pop-up that comes up
for DrawPolygon). So how does one now draw a Polygon with the Graphics
class now?



IntelliSense(前瞻弹出窗口)只能在一个C ++中运行

代码语法:旧的托管C ++语法或新的C ++ / CLI

语法。如果解决方案中的项目混合了两者,那么智能感知会让人感到困惑。 (实际上,在某些情况下,如果你开始使用旧语法并将其设置为新语法,它也可能会混淆
。)


如果你想当你有一些混合语法的b $ b解决方案,你可以创建一个新的解决方案,在新语法中获得一些

函数原型的IntelliSense只有一个项目

'用新语法编译。该项目中的IntelliSense将显示您想要看到的内容:仅使用新语法的原型。

您可以在混合中编写代码时将其用作帮助-syntax"

解决方案。


我希望这会有所帮助。


谢谢,

-

Tarek Madkour,Visual C ++团队

此帖子提供按现状没有保证,并且授予

没有权利。



IntelliSense (the look-ahead popup) can only work in one C++ managed
code syntax: either the old managed C++ syntax or the new C++/CLI
syntax. When you have projects in the solution that have a mix of both,
IntelliSense gets confused. (In reality, in some situations it may also
get confused if you started with old syntax and set it to new syntax).

If you would like to get IntelliSense on the prototypes of some
functions in the new syntax when you have some of those "mixed-syntax"
solutions, you can just create a new solution that has only one project
that''s compiled with the new syntax. IntelliSense in that project will
show exactly what you want to see: prototypes in the new syntax only.
You can use that as help when writing code in the "mixed-syntax"
solutions.

I hope this helps.

Thanks,
--
Tarek Madkour, Visual C++ Team
This posting is provided "AS IS" with no warranties, and confers
no rights.


Peter Oliphant写道:
Peter Oliphant wrote:

图形方法例如DrawPolygon()显然不再编译。
给出的唯一版本是使用旧语法格式的
必需__gc Points []数组。给出了这个
函数的无/ clr兼容过载(至少在DrawPolygon的前瞻弹出窗口中没有)。那么现在如何使用
Graphics类绘制Polygon?

Graphics methods such as DrawPolygon() apparently no longer compile.
The only versions given are the ones using old syntax format for the
required __gc Points[] array. No /clr compatible overload of this
function is given (at least not in the look-ahead pop-up that comes
up for DrawPolygon). So how does one now draw a Polygon with the
Graphics class now?




IntelliSense不是,也从来没有参考过什么是有效的

什么不是,你不应该依赖它。参考是:

1)MSDN。

2)编译器错误消息。


如果IntelliSense没有给出您认为正确的sytnax,只需

手工编写并尝试编译它。


这用/ clr编译(它是's从MSDN文档复制粘贴)和

它在WinForm的Paint处理程序中正常工作:


Pen ^ blackPen = gcnew Pen(Color :: Black) ,3.0f);

Point point1 = Point(50,50);

Point point2 = Point(100,25);

Point point3 = Point(200,5);

Point point4 = Point(250,50);

Point point5 = Point(300,100);

Point point6 = Point(350,200);

Point point7 = Point(250,250);

array< Point> ^ curvePoints =

{point1 ,point2,point3,point4,point5,point6,point7};


e-> Graphics-> DrawPolygon(blackPen,curvePoints);

/ / e是有效的PaintEventArgs


Arnaud

MVP - VC



IntelliSense is not and has never been the reference to say what is valid
and what is not, you shouldn''t rely on it. The reference is :
1) MSDN.
2) The compiler error messages.

If IntelliSense doesn''t give what you think is the correct sytnax, just
write it by hand and try to compile it.

This does compile with /clr (it''s a copy-paste from MSDN documentation) and
it works correctly in the Paint handler of a WinForm :

Pen^ blackPen = gcnew Pen( Color::Black,3.0f );
Point point1 = Point(50,50);
Point point2 = Point(100,25);
Point point3 = Point(200,5);
Point point4 = Point(250,50);
Point point5 = Point(300,100);
Point point6 = Point(350,200);
Point point7 = Point(250,250);
array<Point>^ curvePoints =
{point1,point2,point3,point4,point5,point6,point7} ;

e->Graphics->DrawPolygon( blackPen, curvePoints );
//e is a valid PaintEventArgs

Arnaud
MVP - VC


这篇关于从2003年到2005年的转变太难了的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆