#include <afxwin.h>
#include <afxext.h>
#include "resource.h"class MyFrameWnd : public CFrameWnd
{
DECLARE_DYNCREATE(MyFrameWnd)
public :
MyFrameWnd()
{
// Create(0,"ddd");
}
};
IMPLEMENT_DYNCREATE(MyFrameWnd,CFrameWnd)
class mydoc : public CDocument
{
DECLARE_DYNCREATE(mydoc)
public :
CString s;
CPoint point; mydoc()
{
s="Welcome to SDI";
point.x=250;
point.y=100;
}
BOOL OnNewDocument()
{
::AfxMessageBox("OnNewDocument");
return TRUE;
}
};IMPLEMENT_DYNCREATE(mydoc,CDocument)class myview : public CView
{
     DECLARE_DYNCREATE(myview)
public :
void OnDraw(CDC *d)
{
mydoc *b;
b=(mydoc *)m_pDocument;
d->SetTextColor(RGB(0,0,255));
d->TextOut(b->point.x,b->point.y,b->s);
} void OnLButtonDown(UINT i,CPoint p)
{
mydoc *b;
b=(mydoc *)m_pDocument;
b->point.x=p.x;
b->point.y=p.y;
Invalidate(); }
int OnCreate(LPCREATESTRUCT lpCreateStruct2)
    {
::AfxMessageBox("OnCreate");
return 1;
} DECLARE_MESSAGE_MAP()
};IMPLEMENT_DYNCREATE(myview,CView)BEGIN_MESSAGE_MAP(myview,CView)
ON_WM_CREATE()//如果注释掉这个就没有问题??????但OnCreate不能够映射了
ON_WM_LBUTTONDOWN()
END_MESSAGE_MAP()class myApp : public CWinApp
{
public :
int InitInstance()
{
CSingleDocTemplate *y;
CRuntimeClass *w,*d,*v;
//d=((CRuntimeClass*)(&mydoc::classmydoc));
d=RUNTIME_CLASS(mydoc);
w=RUNTIME_CLASS(MyFrameWnd);
v=RUNTIME_CLASS(myview);
y=new CSingleDocTemplate(IDR_MENU1,d,w,v);
AddDocTemplate(y);
OnFileNew();
return 1;
}};
myApp a;********************************
在资源中有字符串AFX_IDS_UNTITLED  “aa”
还有一个菜单IDR_MENU1
错误 "0x004018b9"指令引用的"0x00000058"内存。该内存不能为"read"

解决方案 »

  1.   

    当出现错误时,按“retry”,然后在call stack list中回溯检查
      

  2.   

    你在OnCreate中做了什么?代码!!
      

  3.   

    应该在OnCreate中
    return 0;吧?
      

  4.   

    进入DEBUG调试,查询错误代码多是指针没有释放的原因http://community.csdn.net/Expert/topic/2971/2971645.xml?temp=.244961
      

  5.   

    OnCreate中return 0;和return 1;效果一样
      

  6.   

    引自MSDN:
    OnCreate must return 0 to continue the creation of the CWnd object. If the application returns –1, the window will be destroyed.
      

  7.   

    也许你应该添加:使用一下基类的处理,MFC太让人迷茫了!
    if (CView::OnCreate(lpCreateStruct) == -1)
    return -1;
    else
    return 0;
      

  8.   

    The CREATESTRUCT structure contains copies of the parameters used to create the window.
      

  9.   

    0x004018b9,根据MAP文件,看下是什么代码。
      

  10.   

    y=new CSingleDocTemplate(IDR_MENU1,d,w,v);
    ->
    y = new CSingleDocTemplate(IDR_MAINFRAME, d, w, v);
      

  11.   

    IDR_MENU1是我用的菜单,我没有用系统菜单
      

  12.   

    0001:00000890       ??1myApp@@UAE@XZ           00401890 f i chapt6SDI.obj
    0001:000008c0       ??0myApp@@QAE@XZ           004018c0 f i chapt6SDI.obj
    0001:00000900       ?InitInstance@myApp@@UAEHXZ 00401900 f i chapt6SDI.obj0x004018b9的位置找到了,但我不知道是不是myApp的InitInstance函数崩溃,又象是OmyApp???
      

  13.   

    在 debug 下调试一下啊!
      

  14.   

    int OnCreate(LPCREATESTRUCT lpCreateStruct2)
        {
    if (CView::OnCreate(lpCreateStruct2) == -1)
    return -1;//加上这两句

    ::AfxMessageBox("OnCreate");
    return 1;
    }
      

  15.   

    0x004018b9-0x400000-0x1000=0x000008b9
     49 0001:000007d7    80 0001:00000900    
    80行崩溃地址
      

  16.   

    zhaogaojian(米柑年成) 高手,你可以说一下为什么吗?谢谢
      

  17.   

    这个崩溃地址不准确,zhaogaojian(米柑年成) 高手,你就花几分钟讲一下吧?