读书人

受不了这该死的delete[]解决方案

发布时间: 2012-02-02 23:57:14 作者: rapoo

受不了这该死的delete[]
HWND ieHWND = ::FindWindow(L "IEFrame ",NULL);
CWnd* ieWnd = CWnd::FromHandle(ieHWND);

//CWnd* addressEditWnd = ieWnd-> FindWindowW(_T( "Edit "),NULL);

//int textLen = addressEditWnd-> GetWindowTextLengthW();
//LPTSTR text = new TCHAR[textLen];
//addressEditWnd-> GetWindowTextW(text,textLen);

//CWnd* workerWWnd = ieWnd-> FindWindowW(L "WorkerW ",NULL);
//CWnd* reBarWindow32Wnd = workerWWnd-> FindWindowW(L "ReBarWindow32 ",NULL);
//CWnd* comboBoxEx32Wnd = workerWWnd-> FindWindowW(L "ComboBoxEx32 ",NULL);

//int textLen = ieWnd-> GetWindowTextLengthW();
//LPTSTR text = new TCHAR[textLen];
//ieWnd-> GetWindowTextW(text,textLen);

//if (text != NULL)
//{
//delete[] text;
//}

LPWSTR buffer = new WCHAR[7];
::GetClassName(ieWnd-> m_hWnd,buffer,8);

if (buffer != NULL)
{
delete[] buffer;
}

高人们为什么删除buffer时会出错?

[解决办法]
越界访问过了的内存块,delete就会出错。

读书人网 >VC/MFC

热点推荐