"System.AccessViolationException"类型未经处理的异常在CTestDlg.exe....请问这是什么错啊?

cabinriver 2014-12-02 02:30:00
错误如下:

"System.AccessViolationException"类型未经处理的异常在CTestDlg.exe..
其它信息:尝试读取或写入受保护的内存。这通常指示其它内存已损坏。

错误的最后指向是在

BOOL CTestDlg::OnWndMsg(UINT message, WPARAM wParam, LPARAM lParam, LRESULT* pResult)
{
if(WM_MOUSEMOVE==message)
{
if(wParam == MK_LBUTTON)
wParam = 0;
}
return CDialogEx::OnWndMsg(message, wParam, lParam, pResult);
}


请问这个错误是什么原因导致的?运行程序时会不定时的出现,目前还没找到是什么原因,请高手指教...
...全文
228 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
向立天 2015-01-06
  • 打赏
  • 举报
回复
您好 我是本版版主 此帖已多日无人关注 请您及时结帖 如您认为问题没有解决可按无满意结帖处理 另外本版设置了疑难问题汇总帖 并已在版面置顶 相关规定其帖子中有说明 您可以根据规定提交您帖子的链接 如您目前不想结帖只需回帖说明 我们会删除此结帖通知 见此回复三日内无回应 我们将强制结帖 相关规定详见界面界面版关于版主结帖工作的具体办法
schlafenhamster 2014-12-02
  • 打赏
  • 举报
回复
wparam=MK_LBUTTON(0x0001) 鼠标左键被按下 if(wParam == MK_LBUTTON) wParam = 0; 、、、、、、、、、、、、、、、、、、、、 wParam = 0; 改 wParam = wParam ; //试试。
oyljerry 2014-12-02
  • 打赏
  • 举报
回复
你用VC的话,跟.Net Framework没什么关系
cabinriver 2014-12-02
  • 打赏
  • 举报
回复
引用 2 楼 oyljerry 的回复:
是不是窗口消息等有问题,或者你消息绑定不对等。
消息绑定应该没问题,因为不是每次都出错。这个是偶然发生的,但是多点几次就总会发生。网上有人说可能是FrameWork的问题,说装4.5就没事了,但我的系统是XP的,装不了4.5来着.....
oyljerry 2014-12-02
  • 打赏
  • 举报
回复
是不是窗口消息等有问题,或者你消息绑定不对等。
hubo86915531 2014-12-02
  • 打赏
  • 举报
回复
学会调试是一个合格程序员的必修课 当发生错误无从下手时屏蔽一部分代码 然后再调试 接着 放开一小部分 再调试 指导找到正在原因
VC PICTURE控件的使用,如何加载背景图片2009年04月19日 星期日 15:02vc picture控件的分类总结: (一) 非动态显示图片(即图片先通过资源管理器载入,有一个固定ID) (二) 动态载入图片(即只需要在程序中指定图片的路径即可载入) 为方便说明,我们已经建好一个基于对话框的工程,名为Ttest. 对话框类为CTestDlg (一) vc picture控件非动态载入图片. 方法1.先从最简单的开始,用picture 控件来实现. 步骤: 先在资源里Import一张图片,ID为IDB_BITMAP2 然后在对话框上添加一个picture控件,右键点击打开属性, 将type下拉框选择BITMAP,紧跟着下面就出现一个Image下拉框, 拉开就会看到所有已经载入好的图片, 选择你要的图片.运行程序即可看到. 方法2vc picture控件.通过背景图 同样如上,先载入一张图片,ID为IDB_BITMAP2 TestDlg.h中 CBrush m_brBk;//在public中定义 TestDlg.cpp中 在初始化函数OnInitDialog()中加入: BOOL CTestDlg::OnInitDialog() { CDialog::OnInitDialog(); CBitmap bmp; bmp.LoadBitmap(IDB_BITMAP2); m_brBk.CreatePatternBrush(&bmp); bmp.DeleteObject(); return TRUE; // return TRUE unless you set the focus to a control } 在打开类向导,找到WM_CTLCOLOR消息,重载得对应函数OnCtlColor(),添加如下: HBRUSH CTestDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor) { HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor); if (pWnd == this) { return m_brBk; } return hbr; } (二) vc picture控件动态载入图片. 方法3 图像控件(本例用KoDak 图像编辑控件) 1. 首先应该保证系统中有这个控件。注意,它不能单独使用,必须和其他几个控件(特别是Imgcmn.dll)一同使用。如果没有,从别的机器上copy过来即可。这几个文件是Imgadmin.ocx,Imgcmn.dll,Imgedit.ocx,Imgscan.ocx,Imgshl.dll,Imgthumb.ocx,Imgutil.dll,把它们copy到windows\system目录下,然后用regsvr32.exe将它们分别注册。 2. 打开工程,进入资源管理器,在对话框上单击右键,单击Insert Activex control… 选择Kodak图象编辑控件,大小任意。 3. 在对话框上选中该控件,为其添加变量:m_ctrlPicture。。 4. 在BOOL CTestDlg::OnInitDialog()添加如下: BOOL CTestDlg::OnInitDialog() { CDialog::OnInitDialog(); m_ctrlPicture.SetImage("aa.jpg"); //保证图像在工程目录下,也可以写绝对路径 m_ctrlPicture.Display(); return TRUE; // return TRUE unless you set the focus to a control // EXCEPTION: OCX Property Pages should return FALSE } 编译运行就OK了,此种方法的好处就是可能针对多种图像格式. 方法4 vc picture控件通过CBitmap,HBITMAP,直接用OnPaint()绘制 首先在CTestDlg类中声明一个变量: CBitmap m_bmp; 然后我们在对话框中加入一个picture 标签,名为IDC_STATIC1 然后: BOOL CDisplayPic::OnInitDialog() { CDialog::OnInitDialog(); if( m_bmp.m_hObject != NULL )//判断 m_bmp.DeleteObject(); /////////载入图片 HBITMAP hbmp = (HBITMAP)::LoadImage(AfxGetInstanceHandle(), "c:\\aaa.bmp", IMAGE_BITMAP, 0, 0, LR_CREATEDIBSECTION|LR_LOADFROMFILE); if( hbmp == NULL ) return FALSE; ///////////////////////该断程序用来取得加载的BMP的信息//////////////////////// m_bmp.Attach( hbmp ); DIBSECTION ds; BITMAPINFOHEADER &bminfo = ds.dsBmih; m_bmp.GetObject( sizeof(ds), &ds ); int cx=bminfo.biWidth; //得到图像宽度 int cy=bminfo.biHeight; //得到图像高度 /////////////////// //////////////////////////////// /////////////得到了图像的宽度和高度后,我们就可以对图像大小进行适应,即调整控件的大小,让它正好显示一张图片/////////////////////////// CRect rect; GetDlgItem(IDC_STATIC1)->GetWindowRect(&rect); ScreenToClient(&rect); GetDlgItem(IDC_STATIC1)->MoveWindow(rect.left,rect.top,cx,cy,true);//调整大小 return TRUE; // return TRUE unless you set the focus to a control // EXCEPTION: OCX Property Pages should return FALSE } 图片加载成功了,标签大小也适应了,下面就是绘制绘制图像了,打开类向导,重载WM_PAINT消息 void CDisplayPic::OnPaint() { //////////////以下三种情况任选一种会是不同效果(只能一种存在)/////////// //CPaintDC dc(this); //若用此句,得到的是对话框的DC,图片将被绘制在对话框上. CPaintDC dc(GetDlgItem(IDC_STATIC1)); //用此句,得到picture控件的DC,图像将被绘制在控件上 // CDC dc; // dc.m_hDC=::GetDC(NULL); //若用此两句,得到的是屏幕的DC,图片将被绘制在屏幕上/////////////////////////////////////////////////////// CRect rcclient; GetDlgItem(IDC_STATIC1)->GetClientRect(&rcclient); CDC memdc; memdc.CreateCompatibleDC(&dc); CBitmap bitmap; bitmap.CreateCompatibleBitmap(&dc, rcclient.Width(), rcclient.Height()); memdc.SelectObject( &bitmap ); CWnd::DefWindowProc(WM_PAINT, (WPARAM)memdc.m_hDC , 0); CDC maskdc; maskdc.CreateCompatibleDC(&dc); CBitmap maskbitmap; maskbitmap.CreateBitmap(rcclient.Width(), rcclient.Height(), 1, 1, NULL); maskdc.SelectObject( &maskbitmap ); maskdc.BitBlt( 0, 0, rcclient.Width(), rcclient.Height(), &memdc, rcclient.left, rcclient.top, SRCCOPY); CBrush brush; brush.CreatePatternBrush(&m_bmp); dc.FillRect(rcclient, &brush); dc.BitBlt(rcclient.left, rcclient.top, rcclient.Width(), rcclient.Height(), &memdc, rcclient.left, rcclient.top,SRCPAINT); brush.DeleteObject(); // Do not call CDialog::OnPaint() for painting messages }
基于DirectSound的简易播放器 #include "stdafx.h" #include "test.h" #include "testDlg.h" #include "process.h" #ifdef _DEBUG #define new DEBUG_NEW #endif // CAboutDlg dialog used for App About class CAboutDlg : public CDialog { public: CAboutDlg(); // Dialog Data enum { IDD = IDD_ABOUTBOX }; protected: virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support // Implementation protected: DECLARE_MESSAGE_MAP() }; CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD) { } void CAboutDlg::DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX); } BEGIN_MESSAGE_MAP(CAboutDlg, CDialog) END_MESSAGE_MAP() // CtestDlg dialog CtestDlg::CtestDlg(CWnd* pParent /*=NULL*/) : CDialog(CtestDlg::IDD, pParent) { m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME); } void CtestDlg::DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX); } BEGIN_MESSAGE_MAP(CtestDlg, CDialog) ON_WM_SYSCOMMAND() ON_WM_PAINT() ON_WM_QUERYDRAGICON() //}}AFX_MSG_MAP ON_BN_CLICKED(IDC_BUTTON_OPEN, &CtestDlg::OnBnClickedButtonOpen) ON_BN_CLICKED(IDC_BUTTON_PLAY, &CtestDlg::OnBnClickedButtonPlay) ON_WM_DESTROY() ON_BN_CLICKED(IDC_BUTTON_STOP, &CtestDlg::OnBnClickedButtonStop) END_MESSAGE_MAP() //ON_BN_CLICKED(IDC_Sound_Play, OnSound2) //ON_BN_CLICKED(IDC_Sound_stop, OnSound1) //ON_BN_CLICKED(IDC_sound_pause, OnBothSounds) //ON_WM_DESTROY() //ON_BN_CLICKED(IDC_BUTTON_Slow, OnBUTTONSlow) //ON_BN_CLICKED(IDC_BUTTON_Fast, OnBUTTONFast) //ON_BN_CLICKED(IDC_BUTTON_Normal, OnBUTTONNormal) // CtestDlg message handlers BOOL CtestDlg::OnInitDialog() { CDialog::OnInitDialog(); // Add "About..." menu item to system menu. // IDM_ABOUTBOX must be in the system command range. ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX); ASSERT(IDM_ABOUTBOX < 0xF000); CMenu* pSysMenu = GetSystemMenu(FALSE); if (pSysMenu != NULL) { CString strAboutMenu; strAboutMenu.LoadString(IDS_ABOUTBOX); if (!strAboutMenu.IsEmpty()) { pSysMenu->AppendMenu(MF_SEPARATOR); pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu); } } // Set the icon for this dialog. The framework does this automatically // when the application's main window is not a dialog SetIcon(m_hIcon, TRUE); // Set big icon SetIcon(m_hIcon, FALSE); // Set small icon // TODO: Add extra initialization here m_sndSound1 = new CDirectSound(); if(!m_sndSound1) { exit(-1); } return TRUE; // return TRUE unless you set the focus to a control } void CtestDlg::OnSysCommand(UINT nID, LPARAM lParam) { if ((nID & 0xFFF0) == IDM_ABOUTBOX) { CAboutDlg dlgAbout; dlgAbout.DoModal(); } else { CDialog::OnSysCommand(nID, lParam); } } // If you add a minimize button to your dialog, you will need the code below // to draw the icon. For MFC applications using the document/view model, // this is automatically done for you by the framework. void CtestDlg::OnPaint() { if (IsIconic()) { CPaintDC dc(this); // device context for painting SendMessage(WM_ICONERASEBKGND, reinterpret_cast(dc.GetSafeHdc()), 0); // Center icon in client rectangle int cxIcon = GetSystemMetrics(SM_CXICON); int cyIcon = GetSystemMetrics(SM_CYICON); CRect rect; GetClientRect(&rect); int x = (rect.Width() - cxIcon + 1) / 2; int y = (rect.Height() - cyIcon + 1) / 2; // Draw the icon dc.DrawIcon(x, y, m_hIcon); } else { CDialog::OnPaint(); } } // The system calls this function to obtain the cursor to display while the user drags // the minimized window. HCURSOR CtestDlg::OnQueryDragIcon() { return static_cast(m_hIcon); } //--------------------------------------------------------------------------------- void CtestDlg::OnBnClickedButtonOpen() { // TODO: Add your control notification handler code here LPCTSTR lpszFilter =L"Wave File(*.wav)|*.wav|All Files|*.*||"; CFileDialog dlg(TRUE,NULL,NULL,/*OFN_HIDEREADONLY |*/ OFN_OVERWRITEPROMPT,lpszFilter); if(dlg.DoModal()==IDOK) { m_soundfile = dlg.GetPathName(); } } // unsigned int WINAPI FileReadProc(LPVOID pOwner) { CtestDlg* pThis = (CtestDlg*)pOwner; pThis->ReadFileProc(); return 1; } // typedef struct _WAVE_FORMAT { WORD AudioFormat; WORD NumChannels; DWORD SampleRate; DWORD ByteRate; WORD BlockAlign; WORD BitsPerSample; }WAVE_FORMAT,*PWAVE_FORMAT; void CtestDlg::OnBnClickedButtonPlay() { // TODO: Add your control notification handler code here if(m_soundfile.IsEmpty()) { MessageBox(L"请选中播放文件!"); return; } USES_CONVERSION; fp = fopen(W2A(m_soundfile.GetBuffer(m_soundfile.GetLength())),"rb"); if(NULL == fp) { MessageBox(L"打开所所定的播放文件失败,请确认文件是否存在!"); return; } fseek(fp,20,0); //Skip previous 20 bytes RIFF header WAVE_FORMAT waveFormat; int nLen =fread(&waveFormat,1,sizeof(WAVE_FORMAT),fp); AUDIO_CONFIG WaveHead; WaveHead.wFormatTag = 1; WaveHead.nChannels = 2; WaveHead.nSamplesPerSec = 44100; WaveHead.nAvgBytesPerSec = 176400; WaveHead.nBlockAlign = 4; WaveHead.wBitsPerSample = 16; WaveHead.nBlockAlign=waveFormat.BlockAlign; WaveHead.nChannels=waveFormat.NumChannels; WaveHead.nSamplesPerSec=waveFormat.SampleRate; WaveHead.wBitsPerSample=waveFormat.BitsPerSample; WaveHead.nAvgBytesPerSec=waveFormat.ByteRate; m_sndSound1->CreateDSound(&WaveHead,8000); fseek(fp,20+sizeof(WAVE_FORMAT),0); unsigned int dwReadID; m_hThread = (HANDLE)_beginthreadex(0,0,FileReadProc,this,0,&dwReadID); Sleep(200); m_bStop = 0; m_bContine = 1; m_sndSound1->Play(); } void CtestDlg::ReadFileProc() { //BYTE buf[1025]; int n = 0; while(1) { BYTE buf[1025]; int nlen; if(m_bStop) break; nlen = fread(buf,1,1024,fp); if(!nlen) break; while(m_sndSound1->WriteDataToBuf(buf,nlen)==-1) { Sleep(100); } } if(fp) { fclose(fp); fp = NULL; } } void CtestDlg::OnDestroy() { CDialog::OnDestroy(); // TODO: Add your message handler code here m_bStop = 1; OnBnClickedButtonStop(); if(m_hThread) { WaitForSingleObject(m_hThread,2000); CloseHandle(m_hThread); m_hThread = 0; } if(m_sndSound1) { delete m_sndSound1; m_sndSound1 = NULL; } if(fp) { fclose(fp); fp = NULL; } } void CtestDlg::OnBnClickedButtonStop() { // TODO: Add your control notification handler code here m_bStop = 1; if(m_hThread) { WaitForSingleObject(m_hThread,2000); CloseHandle(m_hThread); m_hThread = NULL; } m_sndSound1->Stop(); }
======================================================================== MICROSOFT FOUNDATION CLASS LIBRARY : Test ======================================================================== AppWizard has created this Test application for you. This application not only demonstrates the basics of using the Microsoft Foundation classes but is also a starting point for writing your application. This file contains a summary of what you will find in each of the files that make up your Test application. Test.dsp This file (the project file) contains information at the project level and is used to build a single project or subproject. Other users can share the project (.dsp) file, but they should export the makefiles locally. Test.h This is the main header file for the application. It includes other project specific headers (including Resource.h) and declares the CTestApp application class. Test.cpp This is the main application source file that contains the application class CTestApp. Test.rc This is a listing of all of the Microsoft Windows resources that the program uses. It includes the icons, bitmaps, and cursors that are stored in the RES subdirectory. This file can be directly edited in Microsoft Visual C++. Test.clw This file contains information used by ClassWizard to edit existing classes or add new classes. ClassWizard also uses this file to store information needed to create and edit message maps and dialog data maps and to create prototype member functions. res\Test.ico This is an icon file, which is used as the application's icon. This icon is included by the main resource file Test.rc. res\Test.rc2 This file contains resources that are not edited by Microsoft Visual C++. You should place all resources not editable by the resource editor in this file. ///////////////////////////////////////////////////////////////////////////// AppWizard creates one dialog cla

15,978

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 界面
社区管理员
  • 界面
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧