error C2065: “CString”: 未声明的标识符

本文介绍在Windows7+VS2010环境下使用GetAdaptersAddresses函数获取物理MAC地址时遇到的编译错误,并提供了解决方案:通过添加afx.h头文件并在项目属性中设置MFC的使用方式。

在编译文章:
使用GetAdaptersAddresses函数获取物理MAC地址中的代码时,出现以下错误:
错误 3 error C2065: “CString”: 未声明的标识符 f:\ccprojects\获取网卡物理地址mac地址\获取网卡物理地址mac地址\temporary.h 13 1 获取网卡物理地址MAC地址

环境:Windows7+VS2010

解决办法:
添加头文件:

#include <afx.h>

项目属性》配置属性》常规》MFC的使用》在静态库中使用MFC

发生错误了已启动生成… 1>------ 已启动生成: 项目: ImageSystem, 配置: Debug Win32 ------ 1>ImageSystemDlg.cpp 1>C:\Users\John\source\repos\ImageSystem\ImageSystem\ImageSystemDlg.cpp(132,26): error C2065: “gt”: 未声明标识符 1>C:\Users\John\source\repos\ImageSystem\ImageSystem\ImageSystemDlg.cpp(132,28): error C2429: 语言功能 "if/switch 中的 init-statement" 需要编译器标志 "/std:c++17" 1>C:\Users\John\source\repos\ImageSystem\ImageSystem\ImageSystemDlg.cpp(141,23): error C2065: “gt”: 未声明标识符 1>C:\Users\John\source\repos\ImageSystem\ImageSystem\ImageSystemDlg.cpp(141,57): error C2660: “SetStretchBltMode”: 函数不接受 1 个参数 1>C:\Program Files (x86)\Windows Kits\10\Include\10.0.19041.0\um\wingdi.h(4584,25): message : 参见“SetStretchBltMode”的声明 1>C:\Users\John\source\repos\ImageSystem\ImageSystem\ImageSystemDlg.cpp(142,26): error C2065: “gt”: 未声明标识符 1>C:\Users\John\source\repos\ImageSystem\ImageSystem\ImageSystemDlg.cpp(142,28): error C2143: 语法错误: 缺少“)”(在“;”的前面) 1>C:\Users\John\source\repos\ImageSystem\ImageSystem\ImageSystemDlg.cpp(142,28): error C2661: “ATL::CImage::StretchBlt”: 没有重载函数接受 1 个参数 1>C:\Users\John\source\repos\ImageSystem\ImageSystem\ImageSystemDlg.cpp(142,30): error C2065: “m_hDC”: 未声明标识符 1>C:\Users\John\source\repos\ImageSystem\ImageSystem\ImageSystemDlg.cpp(142,54): error C2059: 语法错误:“)” 1>C:\Users\John\source\repos\ImageSystem\ImageSystem\ImageSystemDlg.cpp(143,9): error C2065: “gt”: 未声明标识符 1>C:\Users\John\source\repos\ImageSystem\ImageSystem\ImageSystemDlg.cpp(143,38): error C2660: “SetStretchBltMode”: 函数不接受 1 个参数 1>C:\Program Files (x86)\Windows Kits\10\Include\10.0.19041.0\um\wingdi.h(4584,25): message : 参见“SetStretchBltMode”的声明 1>已完成生成项目“ImageSystem.vcxproj”的操作 - 失败。 ========== 生成: 成功 0 个,失败 1 个,最新 0 个,跳过 0 个 ==========
09-04
void CMFCApplication2Dlg::SendCurrentData() { CString strData; m_editSend.GetWindowText(strData); // 获取0D0A添加状态 BOOL bAddCRLF = (m_checkAddCRLF.GetCheck() == BST_CHECKED); if (m_radioHex.GetCheck() == BST_CHECKED) { // HEX模式处理 strData.Remove(' '); int nLen = strData.GetLength() / 2; int nTotalLen = nLen + (bAddCRLF ? 2 : 0); std::vector<BYTE> buffer(nTotalLen); for (int i = 0; i < nLen; i++) { CString hex = strData.Mid(i * 2, 2); sscanf_s(CStringA(hex).GetString(), "%02hhX", &buffer[i]); } // 添加0D0A if (bAddCRLF) { buffer[nLen] = 0x0D; buffer[nLen + 1] = 0x0A; } SendRawData(buffer.data(), nTotalLen); } else { // ASCII模式处理 if (bAddCRLF) strData += _T("\r\n"); CStringA ansiData(strData); SendRawData(ansiData.GetString(), ansiData.GetLength()); } }1>------ 已启动生成: 项目: MFCApplication2, 配置: Debug Win32 ------ 1>MFCApplication2Dlg.cpp 1>c:\users\administrator\desktop\mfcapplication2\mfcapplication2\mfcapplication2dlg.cpp(274): error C2039: “vector”: 不是“std”的成员 1>c:\program files (x86)\microsoft visual studio\2017\community\vc\tools\msvc\14.16.27023\include\type_traits(17): note: 参见“std”的声明 1>c:\users\administrator\desktop\mfcapplication2\mfcapplication2\mfcapplication2dlg.cpp(274): error C2065: “vector”: 未声明标识符 1>c:\users\administrator\desktop\mfcapplication2\mfcapplication2\mfcapplication2dlg.cpp(274): error C2275: “BYTE”: 将此类型用作表达式非法 1>c:\program files (x86)\windows kits\10\include\10.0.17763.0\shared\minwindef.h(158): note: 参见“BYTE”的声明 1>c:\users\administrator\desktop\mfcapplication2\mfcapplication2\mfcapplication2dlg.cpp(274): error C3861: “buffer”: 找不到标识符 1>c:\users\administrator\desktop\mfcapplication2\mfcapplication2\mfcapplication2dlg.cpp(277): error C2065: “buffer”: 未声明标识符 1>c:\users\administrator\desktop\mfcapplication2\mfcapplication2\mfcapplication2dlg.cpp(277): warning C4473: “sscanf_s”: 没有为格式字符串传递足够的参数 1>c:\users\administrator\desktop\mfcapplication2\mfcapplication2\mfcapplication2dlg.cpp(277): note: 占位符和其参数预计 1 可变参数,但提供的却是 0 参数 1>c:\users\administrator\desktop\mfcapplication2\mfcapplication2\mfcapplication2dlg.cpp(277): note: 缺失的可变参数 1 为格式字符串“%02hhX”所需 1>c:\users\administrator\desktop\mfcapplication2\mfcapplication2\mfcapplication2dlg.cpp(282): error C2065: “buffer”: 未声明标识符 1>c:\users\administrator\desktop\mfcapplication2\mfcapplication2\mfcapplication2dlg.cpp(283): error C2065: “buffer”: 未声明标识符 1>c:\users\administrator\desktop\mfcapplication2\mfcapplication2\mfcapplication2dlg.cpp(286): error C2065: “buffer”: 未声明标识符 1>已完成生成项目“MFCApplication2.vcxproj”的操作 - 失败。 ========== 生成: 成功 0 个,失败 1 个,最新 0 个,跳过 0 个 ==========
10-21
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值