我MFC里建了个MFC类 目的是放些 静态变量 静态函数什么的,可是这个read函数有错误,我找不出在哪,反正程序总是终止,还有一个MessageBox为什么说“非静态成员引用必须与特定对象相对啊”void CPublic::read(char* local)
{
MessageBox((CString)"OK");
//LPCTSTR str1=(LPCTSTR)(LPTSTR)local;
CPublic::str.Empty();
CStdioFile myFile;
CFileException fileException;
if(myFile.Open((LPCTSTR)local,CFile::typeText|CFile::modeReadWrite))
{
myFile.SeekToBegin();
myFile.ReadString(CPublic::str);
}
myFile.Close();}
{
MessageBox((CString)"OK");
//LPCTSTR str1=(LPCTSTR)(LPTSTR)local;
CPublic::str.Empty();
CStdioFile myFile;
CFileException fileException;
if(myFile.Open((LPCTSTR)local,CFile::typeText|CFile::modeReadWrite))
{
myFile.SeekToBegin();
myFile.ReadString(CPublic::str);
}
myFile.Close();}
MessageBox((CString)"OK");
->
AfxMessageBox((CString)"OK");
这样试试
你在debug模式下。运行,看看终止的时候.call stack停在哪里,哪里就有可能是错误的地方
你继承CWnd类,肯定可以用.
其他地方能用也是因为那个类继承了CWnd类.
要么你使用 AfxMessageBox要么你用 ::MessageBox(NULL, "OK", "Yeah", MB_OK);// 第一个参数你可以换成某个窗口句柄,如果调用的时候没有存在的窗口,只能 NULL了。
可以在成员函数里使用MessageBox
您好,
由于您长时间不结贴,上一次答复已超一个月并且已有最佳答案,本人帮你结贴。
若是觉得答案不嘉,请放在本版的疑难杂症帖链接:
http://bbs.csdn.net/topics/390351579。
如果您有什么意见,请您联系我。