CDialog::OnInitDialog();
HANDLE m_hCom;
CString str1;
CString com[20];
//CString comnum ;
//int cnt = 0;
for(int j = 0; j< 20; j++)
{
m_strComPort.Format(_T("COM%d"), j); m_hCom = CreateFile(m_strComPort, GENERIC_READ | GENERIC_WRITE, 0, 0, OPEN_EXISTING, 0, 0); if(m_hCom == INVALID_HANDLE_VALUE)
{
str1+=com[j];
str1+=" ";
}
else
{
cnt = j ; if(cnt)
{
CString comnum ;
comnum.Format(_T("COM%d"), cnt);
m_Combo_CommPort.AddString(comnum);
}
}
为什么我把CString comnum ;放在上面或者定义成一个全局变量就出错啊
错误为error C2601: “CComSelect::OnOK”: 本地函数定义是非法的
1> .\ComSelect.cpp(69): 此行有一个“{”没有匹配项
1>.\ComSelect.cpp(183) : fatal error C1075: 与左侧的 大括号“{”(位于“.\ComSelect.cpp(69)”)匹配之前遇到文件结束
如果把CString comnum ;放在 if(cnt)
{
里面就不报错
但如果变成全局变量或者放在for循环的前面就出现错误 啊
HANDLE m_hCom;
CString str1;
CString com[20];
//CString comnum ;
//int cnt = 0;
for(int j = 0; j< 20; j++)
{
m_strComPort.Format(_T("COM%d"), j); m_hCom = CreateFile(m_strComPort, GENERIC_READ | GENERIC_WRITE, 0, 0, OPEN_EXISTING, 0, 0); if(m_hCom == INVALID_HANDLE_VALUE)
{
str1+=com[j];
str1+=" ";
}
else
{
cnt = j ; if(cnt)
{
CString comnum ;
comnum.Format(_T("COM%d"), cnt);
m_Combo_CommPort.AddString(comnum);
}
}
为什么我把CString comnum ;放在上面或者定义成一个全局变量就出错啊
错误为error C2601: “CComSelect::OnOK”: 本地函数定义是非法的
1> .\ComSelect.cpp(69): 此行有一个“{”没有匹配项
1>.\ComSelect.cpp(183) : fatal error C1075: 与左侧的 大括号“{”(位于“.\ComSelect.cpp(69)”)匹配之前遇到文件结束
如果把CString comnum ;放在 if(cnt)
{
里面就不报错
但如果变成全局变量或者放在for循环的前面就出现错误 啊
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货