vc6->vc8 error c2440

vc6->vc7的系列问题及解决方法-1 zz
2006-07-19 09:57

最近由于工作需要,把项目从vc6升级到vc7(vc.net2003)。升级过程遇到些问题,记录于此。

1. 编译时出现:WINVER not defined. Defaulting to 0X0501 (Windows XP and Windows .NET Server)

这个问题是因为没有指定工程要使用的平台SDK的版本。

Minimum system requiredMacros to define
Windows Server 2003 family_WIN32_WINNT>=0X0502
Windows XP_WIN32_WINNT>=0X0501
Windows 2000_WIN32_WINNT>=0X0500
Windows NT 4.0_WIN32_WINNT>=0X0400
Windows Me_WIN32_WINDOWS=0X0490
Windows 98_WIN32_WINDOWS>=0X0410
Internet Explorer 6.0_WIN32_IE>=0X0600
Internet Explorer 5.01, 5.5_WIN32_IE>=0X0501
Internet Explorer 5.0, 5.0a, 5.0b_WIN32_IE>=0X0500
Internet Explorer 4.01_WIN32_IE>=0X0401
Internet Explorer 4.0_WIN32_IE>=0X0400
Internet Explorer 3.0, 3.01, 3.02_WIN32_IE>=0X0300

解决办法:

属性,C/C++,命令行,附加项中添加 /D _WIN32_WINNT=0x0501 (因为我是在xp下工作的所以是0x0501)

 

2. Link时出现:LINK : warning LNK4075: 忽略”/EDITANDCONTINUE”(由于”/INCREMENTAL:NO”规范)

这个问题是因为在vc6中,工程使用的增量编译。

解决办法:

属性,链接器,常规,启动增量链接 选择 是(INCREMENTAL)

 

3. 编译时出现:warning C4129: “U” : 不可识别的字符转义序列
error C3847: 通用字符中的错误符号;必须使用十六进制数字

原因:为开发全球通用的应用程序,.NET Framework 使用 Unicode UTF-16(Unicode 转换格式,16 位编码形式)来表示字符。在某些情况下,.NET Framework 在内部使用 UTF-8。引入通用字符名称的格式是 /u####/U########

解决办法:
//#include MAKEPATH(MAIN_IMAGE_PATH, FunUtil//Unit_star.txt)
#include “..//ImageData//ML128160//FunUtil//Unit_star.txt”

 

4. 链接时出现:LIBCMTD.lib(crt0dat.obj) : error LNK2005: _exit 已经在 MSVCRTD.lib(MSVCR71D.dll) 中定义 等类似错误

原因:

Run-Time Library

•Run-Time Library是编译器提供的标准库,提供一些基本的库函数和系统调用。
我们一般使用的Run-Time Library是C Run-Time Libraries。当然也有Standard C++ libraries。
CRun-Time Libraries实现ANSI C的标准库。VC安装目录的CRT目录有C Run-Time库的大部分源代码。 CRun-Time Libraries有静态库版本,也有动态链接库版本;有单线程版本,也有多线程版本;还有调试和非调试版本。
•动态链接库版本:
/MD Multithreaded DLL 使用导入库MSVCRT.LIB
/MDd Debug Multithreaded DLL 使用导入库MSVCRTD.LIB
•静态库版本:
/ML Single-Threaded 使用静态库LIBC.LIB
/MLd Debug Single-Threaded 使用静态库LIBCD.LIB
/MT Multithreaded 使用静态库LIBCMT.LIB
/MTd Debug Multithreaded 使用静态库LIBCMTD.LIB
若要使用此运行时库请忽略这些库
单线程 (libc.lib)libcmt.lib、msvcrt.lib、libcd.lib、libcmtd.lib、msvcrtd.lib
多线程 (libcmt.lib)libc.lib、msvcrt.lib、libcd.lib、libcmtd.lib、msvcrtd.lib
使用 DLL 的多线程 (msvcrt.lib)libc.lib、libcmt.lib、libcd.lib、libcmtd.lib、msvcrtd.lib
调试单线程 (libcd.lib)libc.lib、libcmt.lib、msvcrt.lib、libcmtd.lib、msvcrtd.lib
调试多线程 (libcmtd.lib)libc.lib、libcmt.lib、msvcrt.lib、libcd.lib、msvcrtd.lib
使用 DLL 的调试多线程 (msvcrtd.lib)libc.lib、libcmt.lib、msvcrt.lib、libcd.lib、libcmtd.lib

解决方法:

属性,链接器,输入,忽略指定库 libc.lib、libcmt.lib、msvcrt.lib、libcd.lib、libcmtd.lib (这是我需要忽略的,你可以根据你工程的实际情况选择。)

--------------------------------------------------------------------------
vc6->vc7的系列问题及解决方法-2 (ON_MESSAGE出错)zz
2006-07-19 10:06

error C2440: “static_cast” : 无法从“void (__thiscall COpcDlg::* )(UINT,LONG)”转换为“LRESULT (__thiscall CWnd::* )(WPARAM,LPARAM)”

在VC.NET里的ON_MESSAGE里用了static_cast类型安全转换,如下
#define ON_MESSAGE(message, memberFxn) /
{ message, 0, 0, 0, AfxSig_lwl, /
(AFX_PMSG)(AFX_PMSGW) /
(static_cast< LRESULT (AFX_MSG_CALL CWnd::*)(WPARAM, LPARAM) > /
(memberFxn)) },
函数的返回型为LRESULT 而不是void了,因此,在程序中将
ON_MESSAGE(WM_ARROW_UP,OnArrowUp)
里的OnArrowUp函数返回型别改为LRESULT即可。
一般在头文件里定义:
afx_msg void OnArrowUp(UINT wparam,LONG lparam);
改成
afx_msg LRESULT OnArrowUp(UINT wparam,LONG lparam);

同时更改.CPP里的实现。
-------------------------------------------------------------------------------
vc6->vc7的系列问题及解决方法-3 (bitset<...>::to_string)
2006-07-19 10:10
vc6:
bitset<8> code;
TRACE( "%s/n", code.to_string() );

vc7:
error C2783: “std::basic_string<_Elem,_Traits,_Ax> std::bitset<_Bits>::to_string(void) const” : 未能推导出“_Elem”的模板
参数,“_Tr”的模板参数,“_Alloc”的模板参数。
改成如下形式就好了,

code.to_string<char,char_traits<char>,allocator<char> >()

写起来麻烦了点,不知道有没有更好的方法~~
-----------------------------------------------------------------------------------------
vc6->vc7的系列问题及解决方法-4 (NMTOOLBAR->NMHDR)
2006-07-19 10:11
vc6:
void CMainFrame::OnToolbarDropDown(NMTOOLBAR* pnmtb, LRESULT *plr)

vc7:
error C2440: “static_cast” : 无法从“void (__thiscall CMainFrame::* )(NMTOOLBARA *,LRESULT *)”转换为“void (__thiscall CCmdTarget::* )(NMHDR *,LRESULT *)”

改成
void CMainFrame::OnToolbarDropDown(NMHDR* pnmhdr, LRESULT *plr)
{
    LPNMTOOLBAR pnmtb = reinterpret_cast<LPNMTOOLBAR>(pnmhdr);
    ...
}
pal_usecs_t usec1 = pal_time_usecs(); DBG_TEST("show start time %d", usec1); char timebuf[25]; char buf[INET_NTOP_BUFSIZ]; UINT32 out_ifx; char pStr[NETIF_ID_STRLEN]; char cli_buf[1024] = {0}; /* TPIMI_PRINT_STR_LEN 256 */ int len = 0; len += snprintf(cli_buf + len, sizeof(cli_buf) - len, "MPLS Layer-2 Virtual Circuit: %s%s, id: %u, create time: %s\r\n", vc->name, vc->fec_type_vc == PW_OWNER_MANUAL ? "(static)" : "", vc->id, sec2wdhms_str(vc->create_time, timebuf, 25)); #if 0 len += snprintf(cli_buf + len, sizeof(cli_buf) - len, " up time: %s, last change time: %s\r\n", sec2wdhms_str(vc->uptime, timebuf, 25), sec2wdhms_str(vc->last_change, timebuf, 25)); if (vc->tunnel_id > 0) len += snprintf(cli_buf + len, sizeof(cli_buf) - len, " Tunnel-Id: %d\r\n", vc->tunnel_id); else if (vc->tunnel_name) len += snprintf(cli_buf + len, sizeof(cli_buf) - len, " Tunnel-Name: %s\r\n", vc->tunnel_name); #endif if (vc->pw_operation_mode == PW_OPERATING_MODE_RAW) { len += snprintf(cli_buf + len, sizeof(cli_buf) - len, " Operating mode : Raw\r\n"); } else if (vc->pw_operation_mode == PW_OPERATING_MODE_TAGGED) { len += snprintf(cli_buf + len, sizeof(cli_buf) - len, " Operating mode : Tagged\r\n"); } if (vc->address.family == AF_INET) { len += snprintf(cli_buf + len, sizeof(cli_buf) - len, " Endpoint-Type : IPv4 Address\r\n"); pal_inet_ntop(AF_INET, &vc->address.u.prefix4, buf, INET_NTOP_BUFSIZ); len += snprintf(cli_buf + len, sizeof(cli_buf) - len, " Endpoint : %s\r\n", buf); } else if (vc->address.family == AF_INET6) { #ifdef HAVE_IPV6 len += snprintf(cli_buf + len, sizeof(cli_buf) - len, " Endpoint-Type : IPv6 Address\r\n"); pal_inet_ntop(AF_INET6, &vc->address.u.prefix6, buf, INET_NTOP_BUFSIZ); len += snprintf(cli_buf + len, sizeof(cli_buf) - len, " Endpoint : %s\r\n", buf); #endif } else { len += snprintf(cli_buf + len, sizeof(cli_buf) - len, " Endpoint: N/A\r\n"); } len += snprintf(cli_buf + len, sizeof(cli_buf) - len, " Remote vc label: %d\r\n", vc->in_label); len += snprintf(cli_buf + len, sizeof(cli_buf) - len, " Local vc label : %d\r\n", vc->out_label); len += snprintf(cli_buf + len, sizeof(cli_buf) - len, " Control Word : %s\r\n", vc->cw ? "Enabled" : "Disabled"); #if 1 tpImiPrintf(printEnv, "%s", cli_buf); memset(cli_buf, 0, 255); len = 0; #endif ipc_netIfKernelIfx2IfIndex(vc->vc_info.if_index, (long *)&out_ifx); if (ipc_netIfIndex2Str(out_ifx, pStr, NETIF_ID_STRLEN) == ERR_NO_ERROR) { len += snprintf(cli_buf + len, sizeof(cli_buf) - len, " Bound to interface : %s\r\n", pStr); } else { len += snprintf(cli_buf + len, sizeof(cli_buf) - len, " Bound to interface : Unknown\r\n"); } #ifdef HAVE_SUBINTERFACE if (is_ifp_subinterface(vc->vc_info.mif->ifp)) nsm_subif_encap_dump(cli, vc->vc_info.mif->ifp); #endif /* HAVE_SUBINTERFACE */ len += snprintf(cli_buf + len, sizeof(cli_buf) - len, " Virtual Circuit Type: %s\r\n", mpls_vc_type_to_str(vc->vc_info.vc_type)); if (vc->vc_info.vc_type == VC_TYPE_ETH_VLAN) { if (vc->vc_info.vlan_id) len += snprintf(cli_buf + len, sizeof(cli_buf) - len, " Vlan Id: %d\r\n", vc->vc_info.vlan_id); if (vc->vc_info.inner_vlan) len += snprintf(cli_buf + len, sizeof(cli_buf) - len, " Inner Vlan Id: %d\r\n", vc->vc_info.inner_vlan); if (vc->vc_info.svlan_tpid) len += snprintf(cli_buf + len, sizeof(cli_buf) - len, " Svlan Tpid: %x\r\n", vc->vc_info.svlan_tpid); } if (vc->vc_info.vc_type == VC_TYPE_ETHERNET) { if (vc->vc_info.svlan_id) len += snprintf(cli_buf + len, sizeof(cli_buf) - len, " Svlan Id: %d\r\n", vc->vc_info.svlan_id); if (vc->vc_info.svlan_tpid) len += snprintf(cli_buf + len, sizeof(cli_buf) - len, " Svlan Tpid: %x\r\n", vc->vc_info.svlan_tpid); } if (vc->vc_info.egress_oper) { len += snprintf(cli_buf + len, sizeof(cli_buf) - len, " Action: %s\r\n", mpls_pw_egr_oper_to_str(vc->vc_info.egress_oper)); } #if 0 if (!CHECK_FLAG(vc->vc_info.conf_flag, (1 << 4))) pal_strcpy(vcstr, "Primary"); else pal_strcpy(vcstr, "Secondary"); len += snprintf(cli_buf + len, sizeof(cli_buf) - len, " Virtual Circuit is configured as %s\r\n", vcstr); #endif if (vc->install == TRUE) { if (IS_NSM_CODE_PW_AC_FAULT(vc->pw_status)) { len += snprintf(cli_buf + len, sizeof(cli_buf) - len, " Virtual Circuit is inactive"); } else { len += snprintf(cli_buf + len, sizeof(cli_buf) - len, " Virtual Circuit is active"); } } else if (CHECK_FLAG(vc->vc_info.conf_flag, (1 << 1))) { len += snprintf(cli_buf + len, sizeof(cli_buf) - len, " Virtual Circuit is standby"); } else { len += snprintf(cli_buf + len, sizeof(cli_buf) - len, " Virtual Circuit is inactive"); } if (vc->state == 3 /* NSM_MPLS_L2_CIRCUIT_UP */) { len += snprintf(cli_buf + len, sizeof(cli_buf) - len, " (UpTime %s) ", sec2wdhms_str(vc->vc_up_time, timebuf, 25)); } else { len += snprintf(cli_buf + len, sizeof(cli_buf) - len, " (Reason: %s)", vc_down_reason_str(vc->last_down_reason)); } len += snprintf(cli_buf + len, sizeof(cli_buf) - len, "\r\n"); tpImiPrintf(printEnv, "%s\r\n", cli_buf); #ifdef HAVE_VCCV l2_circuit_vccv_dump (printEnv, vc); #endif /* HAVE_VCCV */ usec1 = pal_time_usecs(); DBG_TEST("show end time %d", usec1); #if 0 else if (vc->vpls) { struct nsm_vpls_spoke_vc *svc; /* VPLS binding. */ tpImiPrintf(printEnv, " Bound to VPLS instance: %s\r\n", (vc->vpls ? vc->vpls->vpls_name : "none")); svc = nsm_vpls_spoke_vc_lookup_by_name (vc->vpls, vc->name, NSM_FALSE); if (svc) { /* Circuit type is always ETHERNET VPLS. */ tpImiPrintf(printEnv, " Virtual Circuit Type: %s\r\n", mpls_vc_type_to_str (svc->vc_type)); } } #endif /* HAVE_VPLS */ #if 0 AVL_TREE_LOOP (nm->svc_templ_table, svc_templ, avl_node) { if (vc->vc_info && ((pal_strncmp(vc->vc_info.svc_templ_name, svc_templ->name, MAX_SVC_TEMPLATE_NAME)) == 0)) nsm_svc_templ_dump_detail (cli, svc_templ, PAL_TRUE); } #endif 减少上述代码中snprintf的调用次数
最新发布
01-01
//char vcstr[10]; char timebuf[25]; char buf[INET_NTOP_BUFSIZ]; UINT32 out_ifx; char pStr[NETIF_ID_STRLEN]; char cli_buf[255] = {0}; int len = 0; len += snprintf(cli_buf, 255, "MPLS Layer-2 Virtual Circuit: %s%s, id: %u, create time: %s\r\n", vc->name, vc->fec_type_vc == PW_OWNER_MANUAL ? "(static)" : "", vc->id, sec2wdhms_str (vc->create_time, timebuf, 25)); tpImiPrintf(printEnv, "%s", cli_buf); #if 0 tpImiPrintf(printEnv, " up time: %s, last change time: %s\r\n", sec2wdhms_str (vc->uptime, timebuf, 25), sec2wdhms_str (vc->last_change, timebuf, 25)); if (vc->tunnel_id > 0) tpImiPrintf(printEnv, " Tunnel-Id: %d\r\n", vc->tunnel_id); else if (vc->tunnel_name) tpImiPrintf(printEnv, " Tunnel-Name: %s\r\n", vc->tunnel_name); #endif if (vc->pw_operation_mode == PW_OPERATING_MODE_RAW) { tpImiPrintf(printEnv," Operating mode : Raw\r\n"); } else if (vc->pw_operation_mode == PW_OPERATING_MODE_TAGGED) { tpImiPrintf(printEnv," Operating mode : Tagged\r\n"); } /* End-point. */ if (vc->address.family == AF_INET) { tpImiPrintf(printEnv, " Endpoint-Type : IPv4 Address\r\n"); pal_inet_ntop (AF_INET, &vc->address.u.prefix4, buf, INET_NTOP_BUFSIZ); tpImiPrintf(printEnv, " Endpoint : %s\r\n", buf); } else if (vc->address.family == AF_INET6) { #ifdef HAVE_IPV6 tpImiPrintf(printEnv, " Endpoint-Type : IPv6 Address\r\n"); pal_inet_ntop (AF_INET6, &vc->address.u.prefix6, buf, INET_NTOP_BUFSIZ); tpImiPrintf(printEnv, " Endpoint : %s\r\n", buf); #endif /* HAVE_IPV6 */ } else tpImiPrintf(printEnv, " Endpoint: N/A\r\n"); tpImiPrintf(printEnv, " Remote vc label: %d\r\n", vc->in_label); tpImiPrintf(printEnv, " Local vc label : %d\r\n", vc->out_label); /* Control Word. */ tpImiPrintf(printEnv, " Control Word : %s\r\n", vc->cw ? "Enabled" : "Disabled"); /* Outgoing interface. */ ipc_netIfKernelIfx2IfIndex(vc->vc_info.if_index, (long *)&out_ifx); if (ipc_netIfIndex2Str(out_ifx, pStr, NETIF_ID_STRLEN) == ERR_NO_ERROR) { tpImiPrintf(printEnv, " Bound to interface : %s\r\n", pStr); } else { tpImiPrintf(printEnv, " Bound to interface : Unknown\r\n"); } #ifdef HAVE_SUBINTERFACE if (is_ifp_subinterface(vc->vc_info.mif->ifp)) nsm_subif_encap_dump(cli, vc->vc_info.mif->ifp); #endif /* HAVE_SUBINTERFACE */ /* Virtual Circuit type. */ tpImiPrintf(printEnv, " Virtual Circuit Type: %s\r\n", mpls_vc_type_to_str(vc->vc_info.vc_type)); if (vc->vc_info.vc_type == VC_TYPE_ETH_VLAN) { if (vc->vc_info.vlan_id) tpImiPrintf(printEnv, " Vlan Id: %d\r\n",vc->vc_info.vlan_id); if (vc->vc_info.inner_vlan) tpImiPrintf(printEnv, " Inner Vlan Id: %d\r\n",vc->vc_info.inner_vlan); if (vc->vc_info.svlan_tpid) tpImiPrintf(printEnv, " Svlan Tpid: %x\r\n",vc->vc_info.svlan_tpid); } if (vc->vc_info.vc_type == VC_TYPE_ETHERNET) { if (vc->vc_info.svlan_id) tpImiPrintf(printEnv, " Svlan Id: %d\r\n",vc->vc_info.svlan_id); if (vc->vc_info.svlan_tpid) tpImiPrintf(printEnv, " Svlan Tpid: %x\r\n",vc->vc_info.svlan_tpid); } if (vc->vc_info.egress_oper) { tpImiPrintf(printEnv, " Action: %s\r\n",mpls_pw_egr_oper_to_str(vc->vc_info.egress_oper)); } #if 0 /* Set Virtual Circuit Mode */ if (!CHECK_FLAG (vc->vc_info.conf_flag, (1 << 4) /* NSM_MPLS_VC_CONF_SECONDARY */)) pal_strcpy (vcstr, "Primary"); else pal_strcpy (vcstr, "Secondary"); tpImiPrintf(printEnv, " Virtual Circuit is configured as %s\r\n", vcstr); #endif if (vc->install == TRUE) { if (IS_NSM_CODE_PW_AC_FAULT(vc->pw_status)) { tpImiPrintf(printEnv, " Virtual Circuit is inactive"); } else { tpImiPrintf(printEnv, " Virtual Circuit is active"); } } else if (CHECK_FLAG (vc->vc_info.conf_flag, (1 << 1) /* NSM_MPLS_VC_CONF_STANDBY */)) tpImiPrintf(printEnv, " Virtual Circuit is standby"); else tpImiPrintf(printEnv, " Virtual Circuit is inactive"); if (vc->state == 3 /* NSM_MPLS_L2_CIRCUIT_UP */) { tpImiPrintf(printEnv, " (UpTime %s) ", sec2wdhms_str (vc->vc_up_time, timebuf, 25)); } else { tpImiPrintf(printEnv, " (Reason: %s)", vc_down_reason_str (vc->last_down_reason)); } tpImiPrintf(printEnv, "\r\n"); #ifdef HAVE_VCCV l2_circuit_vccv_dump (printEnv, vc); #endif /* HAVE_VCCV */ #if 0 else if (vc->vpls) { struct nsm_vpls_spoke_vc *svc; /* VPLS binding. */ tpImiPrintf(printEnv, " Bound to VPLS instance: %s\r\n", (vc->vpls ? vc->vpls->vpls_name : "none")); svc = nsm_vpls_spoke_vc_lookup_by_name (vc->vpls, vc->name, NSM_FALSE); if (svc) { /* Circuit type is always ETHERNET VPLS. */ tpImiPrintf(printEnv, " Virtual Circuit Type: %s\r\n", mpls_vc_type_to_str (svc->vc_type)); } } #endif /* HAVE_VPLS */ #if 0 AVL_TREE_LOOP (nm->svc_templ_table, svc_templ, avl_node) { if (vc->vc_info && ((pal_strncmp(vc->vc_info.svc_templ_name, svc_templ->name, MAX_SVC_TEMPLATE_NAME)) == 0)) nsm_svc_templ_dump_detail (cli, svc_templ, PAL_TRUE); } #endif tpImiPrintf(printEnv, "\r\n"); 把如上代码改造一下,改为snprintf 到一个buf内,再掉用tmImiPrintf打印,参考 len += snprintf(cli_buf, 255, "MPLS Layer-2 Virtual Circuit: %s%s, id: %u, create time: %s\r\n", vc->name, vc->fec_type_vc == PW_OWNER_MANUAL ? "(static)" : "", vc->id, sec2wdhms_str (vc->create_time, timebuf, 25)); tpImiPrintf(printEnv, "%s", cli_buf),假设buf长度足够
12-30
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值