VC6工程转VC9工程常见错误

本文列举了从Visual C++ 6.0迁移到Visual C++ 2008过程中遇到的常见编译错误及其解决方案,包括循环变量作用域、默认类型声明、函数参数类型转换等问题。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

转载:VC6工程转VC9工程常见错误

1. error C2065: 'i' : undeclared identifier

for循环体定义的循环变量只能在for循环体内使用。例如:

 

  1. for (int i=0; …) {  
  2.   
  3. }  
  4.   
  5. for (i=0; …) { // C2065   
  6.   
  7. }  
  8.   
  9. for (int i=0; …) { // OK   
  10.   
  11. }  

 

2. error C4430: missing type specifier - int assumed. Note: C++ does not support default-int

static/register等变量类型以及函数返回值类型均不能缺省,例如:

 

  1. static count = 0; // C4430   
  2.   
  3. static int count = 0; // OK  

 

3. error C2065: 'afxChNil' : undeclared identifier

函数GetPrivateProfileString的第三个参数可以为NULL了,不再需要“lpszDefault = &afxChNil;”。

4. LINK : fatal error LNK1181: cannot open input file 'ddraw.lib'

VS2008不再自带ddraw.lib,需要安装DirectX SDK。

5. error C2440: 'static_cast' : cannot convert from 'void (__thiscall CXXDlg::* )(BOOL,HTASK)' to 'void (__thiscall CWnd::* )(BOOL,DWORD)'
Cast from base to derived requires dynamic_cast or static_cast

一些消息函数的声明被改变了,例如ON_WM_ACTIVATEAPP,

VC6的版本:

  1. afx_msg void OnActivateApp(BOOL bActive, HTASK hTask);  

VC9的版本:

  1. afx_msg void OnActivateApp(BOOL bActive, DWORD dwThreadID);  

6. error C2471: cannot update program database '…/debug/vc90.pdb'

VS2008的BUG,解决所有的编译错误后,Rebuild就没有了。

7. error C2383: default-arguments are not allowed on this symbol

函数指针的参数不能有缺省参数值。例如:

 

  1. void (*pf)(int = 0); // C2383   
  2.   
  3. void (*pf)(int); // OK   
  4.   
  5. typedef long (CALLBACK* LPFNFUNCNAME)(int val = 0); // C2383   
  6.   
  7. typedef long (CALLBACK* LPFNFUNCNAME)(int val); // OK  

 

8. error C2039: 'ReadHuge' : is not a member of 'CFile'

CFile没有ReadHuge成员了,用Read就可以了。

9. 1>c:/program files/microsoft sdks/windows/v6.0a/include/ws2def.h(91) : warning C4005: 'AF_IPX' : macro redefinition
1> c:/program files/microsoft sdks/windows/v6.0a/include/winsock.h(460) : see previous definition of 'AF_IPX'
1>c:/program files/microsoft sdks/windows/v6.0a/include/ws2def.h(91) : warning C4005: 'AF_IPX' : macro redefinition
1> c:/program files/microsoft sdks/windows/v6.0a/include/winsock.h(460) : see previous definition of 'AF_IPX'

类似的错误和警告,都是因为混用了Winsock.h和Winsock2.h,如果说代码中没有找到相关#include语句,在工程设置C/C++ -> Advanced中打开Show Includes (/showIncludes) 来查看头文件的关联情况。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值