为什么我在OnTimer()中定义字符数组程序运行时会出现“该内存不能为read”异常。附代码:
void CTY_VODDlg::OnTimer(UINT nIDEvent)
{
// TODO: Add your message handler code here and/or call default
CString m_Stop_Str;
char m_Stop_Buf[10];
MCIERROR m_Error=mciSendString ("status movie mode",m_Stop_Buf,strlen(m_Stop_Buf),0);
//l=strlen(m_Stop_Buf);
//m_Stop_Str.Format("%d",m_Stop_Buf);
m_Stop_Str=m_Stop_Buf;
MessageBox(m_Stop_Str);
if(m_Error!=0)
{ KillTimer(1);
MessageBox("出错");
}
if(m_Stop_Str.Left(7)=="stopped")
{
KillTimer(1);
MessageBox(m_Stop_Str);
OnNext();
}
memset(m_Stop_Buf,0,strlen(m_Stop_Buf));
MessageBox("END");
CDialog::OnTimer(nIDEvent);
}
void CTY_VODDlg::OnTimer(UINT nIDEvent)
{
// TODO: Add your message handler code here and/or call default
CString m_Stop_Str;
char m_Stop_Buf[10];
MCIERROR m_Error=mciSendString ("status movie mode",m_Stop_Buf,strlen(m_Stop_Buf),0);
//l=strlen(m_Stop_Buf);
//m_Stop_Str.Format("%d",m_Stop_Buf);
m_Stop_Str=m_Stop_Buf;
MessageBox(m_Stop_Str);
if(m_Error!=0)
{ KillTimer(1);
MessageBox("出错");
}
if(m_Stop_Str.Left(7)=="stopped")
{
KillTimer(1);
MessageBox(m_Stop_Str);
OnNext();
}
memset(m_Stop_Buf,0,strlen(m_Stop_Buf));
MessageBox("END");
CDialog::OnTimer(nIDEvent);
}
解决方案 »
- 在listctrl中删除一个记录,如何同时删除关联在.us文件里的那条记录?
- ~~音频播放器如何从网上获取歌词~~
- LISTVIEW中subitem的pszText能一次添加后自动保存吗?
- RichEdit显示Gif图片的问题
- wininet中可以支持javascript吗?应该怎样实现?
- 一个关于文件检索的问题
- 有的网站提供的VS几百M,有的几G(VS2010)
- 一个简单的问题,超时如何处理?
- 谁有天网防火墙个人版的注册码(SN)
- 求下面的ShowWindow是什么目的,我在我的代码中发现一堆这样的函数,我的程序一个窗口,为什么调用这么多次
- 数据库奇怪问题
- 1万可用分,大家要多少我就散多少(八)
char m_Stop_Buf[10] = {0};
其次if(m_Stop_Str.Left(7)=="stopped")
这里需要先判断m_Stop_Str长度是否大于7
if(m_Error!=0)
{ KillTimer(1);
MessageBox("出错");
}
这个if语句中应该增加return,否则程序会继续执行下去,后续的代码只能带来各种错误。
为什么捕捉不到mci状态呢?每次进入定时器用MessageBox()显示字符串为空
void CTY_VODDlg::OnTimer(UINT nIDEvent)
{
// TODO: Add your message handler code here and/or call default
CString m_Stop_Str;
char m_Stop_Buf[256]={0};
MCIERROR m_Error=mciSendString ("status movie mode",m_Stop_Buf,strlen(m_Stop_Buf),0);
m_Stop_Str.Format("%s",m_Stop_Buf);
MessageBox(m_Stop_Str);
if(m_Error!=0)
{ KillTimer(1);
MessageBox("出错");
}
if(m_Stop_Str.Left(7)=="stopped")
{
KillTimer(1);
MessageBox(m_Stop_Str);
OnNext();//如果播放完毕就立即播放下一首。
}
CDialog::OnTimer(nIDEvent);
}