好像是关于内存的问题。哪位高手帮我看看...
我用C++编了个.cpp的文件,里面把从txt中读来的文本转换成16进制数放到char数组里,运行时没有错误的。现在把它添加到一个MFC中,用网络套接字把这个char数组的数据发送出去,可是一运行就出现下面的错误提示:Debug Assertion Failed! File: afx.inl Line:177...应用程序发生异常 unknown software exception (0x80000003),位置为0x7c92120e
上网查了好多,好像说跟内存泄漏什么的有关,我在MFC里加的内容如下:请懂得朋友帮我看看吧,到底是啥错误啊,为什么挪到这里就不对了呢?
CSendDataDlg::HexToChar(char ch) // Char <->Hex
{
if((ch>='0')&&(ch<='9'))
return ch-0x30;
else if((ch>='A')&&(ch<='F'))
return ch-'A'+10;
else if((ch>='a')&&(ch<='f'))
return ch-'a'+10;
else
return -1;
}
::ifstream myfile("E:\\data.txt");//打开存放数据的文本文件
void CSendDataDlg::OnTimer(UINT nIDEvent)
{
// TODO: Add your message handler code here and/or call default
//发数据
char BfSnd[200];
myfile.getline (BfSnd,sizeof(BfSnd));
str=BfSnd;
unsigned char tmpByte = 0x00;
strLen = str.GetLength(); //////////字符串的长度
unsigned char SendData[200];
memset(SendData, '\0', sizeof(SendData));
DataLen=0; ///////实际发送的字节数
////////////去掉数据中的空格,将两个数字作为一 个16进制数
for (int j=0; DataLen<128,j<strLen; DataLen++,j++)
{
if (str[j] == ' ')
j++;
if(str[j]==' ')
break;
tmpByte =((HexToChar(str[j])<<4)+ HexToChar(str[j+1]));//取低4位然后相加。
SendData[DataLen]=tmpByte;
j++;
}
///////利用套接字发送
int iSend= m_sockSend.SendTo(SendData,DataLen+1,6801,"10.1.34.10",0);
UpdateData(FALSE);
CDialog::OnTimer(nIDEvent);
}
还有call stack里面写着下面一堆内容,但是我太菜了看不懂什么意思:
NTDLL! 7c92120e()
_CrtDbgReport
(int 2, const char * 0x5f4adf34 _szAfxInl, int 177, const char * 0x00000000, const char * 0x00000000) line 353
AfxAssertFailedLine(const char * 0x5f4adf34 _szAfxInl, int 177) line 39 + 20 bytes
CString::operator[](int 33) line 177 + 31 bytes
CSendDataDlg::OnTimer(unsigned int 1) line 273 + 21 bytes
CWnd::OnWndMsg(unsigned int 275, unsigned int 1, long 0, long * 0x0012af80) line 1840
CWnd::WindowProc(unsigned int 275, unsigned int 1, long 0) line 1596 + 30 bytes
AfxCallWndProc(CWnd * 0x0012fe5c, HWND__ * 0x002f0244, unsigned int 275, unsigned int 1, long 0) line 215 + 26 bytes
AfxWndProc(HWND__ * 0x002f0244, unsigned int 275, unsigned int 1, long 0) line 379
AfxWndProcBase(HWND__ * 0x002f0244, unsigned int 275, unsigned int 1, long 0) line 220 + 21 bytes
USER32! 77d18734()
USER32! 77d18816()
USER32! 77d189cd()
USER32! 77d18a10()
USER32! 77d27721()
USER32! 77d249c4()
USER32! 77d3a956()
USER32! 77d3a2bc()
USER32! 77d663fd()
USER32! 77d664a2()
USER32! 77d50877()
USER32! 77d5082f()
__crtMessageBoxA(const char * 0x0012b6f0, const char * 0x102579a0 `string', unsigned int 73746) line 65
CrtMessageWindow(int 2, const char * 0x5f4adf34 _szAfxInl, const char * 0x0012c824, const char * 0x00000000, const char * 0x0012e848) line 520 + 22 bytes
_CrtDbgReport(int 2, const char * 0x5f4adf34 _szAfxInl, int 177, const char * 0x00000000, const char * 0x00000000) line 419 + 76 bytes
AfxAssertFailedLine(const char * 0x5f4adf34 _szAfxInl, int 177) line 39 + 20 bytes
CString::operator[](int 75) line 177 + 31 bytes
CSendDataDlg::OnTimer(unsigned int 1) line 273 + 21 bytes
CWnd::OnWndMsg(unsigned int 275, unsigned int 1, long 0, long * 0x0012fb70) line 1840
CWnd::WindowProc(unsigned int 275, unsigned int 1, long 0) line 1596 + 30 bytes
AfxCallWndProc(CWnd * 0x0012fe5c, HWND__ * 0x002f0244, unsigned int 275, unsigned int 1, long 0) line 215 + 26 bytes
AfxWndProc(HWND__ * 0x002f0244, unsigned int 275, unsigned int 1, long 0) line 379
AfxWndProcBase(HWND__ * 0x002f0244, unsigned int 275, unsigned int 1, long 0) line 220 + 21 bytes
USER32! 77d18734()
USER32! 77d18816()
USER32! 77d189cd()
USER32! 77d196c7()
CWinThread::PumpMessage() line 853
CWnd::RunModalLoop(unsigned long 4) line 3489 + 19 bytes
CDialog::DoModal() line 539 + 12 bytes
CSendDataApp::InitInstance() line 65 + 11 bytes
AfxWinMain(HINSTANCE__ * 0x00400000, HINSTANCE__ * 0x00000000, char * 0x00141f2f, int 1) line 39 + 11 bytes
WinMain(HINSTANCE__ * 0x00400000, HINSTANCE__ * 0x00000000, char * 0x00141f2f, int 1) line 30
WinMainCRTStartup() line 330 + 54 bytes
KERNEL32! 7c817077()