您的位置:首页 > 其它

工程转VC2005的一些注意点回顾

2007-06-24 20:01 323 查看
很多朋友可能也会有从VC6.0,VC03转向VC05的经历,VC05对紧跟C++标准,还有一些编译选项的改变也到置后来自动转换后工程编译不过或者莫名其妙的问题。

强烈建议你转换后看看UpgradeLog.XML这个文件,文件讲述了转换后讲可能出现的问题以及一些解决方法,我就是开始忽略了这个,导致很多问题还在网上google很久才找到答案。

如我的UpgradeLog.XML

Conversion Issues - KPFW32/KPFW32.vcproj:
Visual C++ now provides improved safety in its C and C++ Libraries. This includes new and improved functions, additional checking and validation, and internal design changes. These libraries are turned on by default. You may see some warnings about unsafe functions or parameters when you build your project. The warnings will generally suggest an alternative safer coding style or function. It is advised that you correct these warnings, in order to make your code more safe. Full details can be found in the documentation by searching for 'Security Enhancements in the CRT' and for 'Checked Iterators'.
The C/C++ compiler default settings have been modified to be more compliant with ISO Standard C++. Included in those changes are enforcing Standard C++ for loop scoping and supporting wchar_t as a native type. These changes may cause existing code to no longer compile without changes to the code or the compiler options with which it is built.
Project upgraded successfully.
Due to the requirement that Visual C++ projects produce an embedded (by default) Windows SxS manifest, manifest files in the project are automatically excluded from building with the Manifest Tool. It is recommended that the dependency information contained in any manifest files be converted to "#pragma comment(linker,"<insert dependency here>")" in a header file that is included from your source code. If your project already embeds a manifest in the RT_MANIFEST resource section through a resource (.rc) file, the line will need to be commented out before the project will build correctly.
Due to a conformance change in the C++ compiler, code change may be required before your project will build without errors. Previous versions of the C++ compiler allowed specification of member function pointers by member function name (e.g. MemberFunctionName). The C++ standard requires a fully qualified name with the use of the address-of operator (e.g. &ClassName::MemberFunctionName). If your project contains forms or controls used in the Windows Forms Designer, you may have to change code in InitializeComponent because the designer generated code used the non-conformant syntax in delegate construction (used in event handlers).
第一点讲述了更新更安全CRT库导致的警告或者错误。

第二点主要是VC05默认已经是unicode了,所以以前ansi的程序编译可能出现问题

第三点我开始没有看这个文档,搞了我半天,后来在msdn里面的mvp回答找到说UpgradeLog.XML会有说明,晕

很多朋友可能简单地关掉那个MANIFEST Tool。改成NO,但这个终究不是解决办法,对很多用这个表单导入XP效果的程序会发现后来XP风格不起作用了,下面是目前比较好的做法:(在codeproject里面拷的)

Thanks for bringing this up! I had no idea it was an issue till I tried it! There's a couple things going on here, I'll try to explain it as best as I can.

Visual Studio 2005 automaticlly creates and embeds a manifest file in your MFC or Win32 Project. You'll notice if you go to the project properties of the converted project you'll see Manifest Tool, open that up and select "Input and Output" if you change "Embed Manifest" to "No" you'll notice you no longer get the compile errors. However this is not the solution.

The first thing you'll want to do is remove the manifest.xml file from the project. Then remove the resource itself (open the RT_MANIFEST folder and delete the "1" resource)

Now add this code to the end of your stdafx.h file

#pragma comment(linker,"/manifestdependency:/"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='x86' publicKeyToken='6595b64144ccf1df' language='*'/"")


And you should be stylin again!

Strangely enough it automaticlly does this if your project is unicode enabled. If you want to be really fancy you could add this code:


ifdef _UNICODE

#if defined _M_IX86
#pragma comment(linker,"/manifestdependency:/"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='x86' publicKeyToken='6595b64144ccf1df' language='*'/"")
#elif defined _M_IA64

#pragma comment(linker,"/manifestdependency:/"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='ia64' publicKeyToken='6595b64144ccf1df' language='*'/"")

#elif defined _M_X64

#pragma comment(linker,"/manifestdependency:/"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='amd64' publicKeyToken='6595b64144ccf1df' language='*'/"")

#else

#pragma comment(linker,"/manifestdependency:/"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='*' publicKeyToken='6595b64144ccf1df' language='*'/"")

#endif

#endif


To give credit where credit is due, I pretty much found all the info here to make everything work: http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=143306&SiteID=1[^].

Let me know if this works for you. I will try an update the article with this info as soon as I can verify it works for someone!

Thanks
Kluch


-- modified at 0:31 Friday 16th December, 2005

第四点大概意思是原来取成员函数指针可以通过成员函数名来获得(e.g. MemberFunctionName). 现在为了对应新的编译器要求,需要改成(e.g. &ClassName::MemberFunctionName).

好像我在修改工程中还有一些其他的问题需要改,在另外我的一些转载的文章看看吧,不大记得了。。嘿嘿

记得要看看UpgradeLog.XML
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: