I'm having some nasty problems with the MFC class CFileDialog. I'm simply trying to use it to get the name of a selected file and put it in a text edit box. I have done this many times before and have never had this sort of problem. Here is the code that is producing the error:
void CUpload::OnBrowse()
{
static TCHAR BASED_CODE szFilter[] = "Windows Setup file (*.exe; *.EXE; *.msi ;*.MSI)|*.exe ;*.EXE;*.msi;*.MSI||";
CFileDialog oFileDlg(TRUE,"exe","",OFN_FILEMUSTEXIST|OFN_NOCHANGEDIR, szFilter);
oFileDlg.m_ofn.lpstrTitle = "Select the Installable Application";
if(oFileDlg.DoModal() == IDOK)
{
m_strloc = oFileDlg.GetPathName();
GetDlgItem(IDC_FILELOC)->SetWindowText(m_strloc);
}
}
IDC_FILELOC is the id of the editbox and m_strloc is the variable of the edit box.
When I press the 'browse' (which calls void CUpload::OnBrowse() button the CFileDialog is created and DoModal() is called (causing the dialog to appear). It then lets me select a file. If I press 'Open' it returns IDOK and the file name gets put into the text edit box. If I select 'Cancel' IDCANCEL is returned and anything inside the text edit box is cleared (as it should be). The error doesn't occur untill the destructor is called. Which of course happens when the CFileDialog goes out of scope as soon as the function. Everything I have before then works correctly (I used message boxes to stop determine the point just before it crashes). I even commented out everything but the constructor and still got an error when the destructor is called.
The error message it says when the program crashes when I run it through the debugger says, "Unhandled exception in File Splitter.exe (KERNEL32.DLL): 0xC0000005: Access Violation."
KERNEL32! 7c80979d()
CFileDialog::~CFileDialog() + 71 bytes
CUpload::OnBrowse() line 78 + 18 bytes
_AfxDispatchCmdMsg(CCmdTarget * 0x0012f564 {CUpload hWnd=0x00080786}, unsigned int 1004, int 0, void (void)* 0x00401659 CUpload::OnBrowse(void), void * 0x00000000, unsigned int 12, AFX_CMDHANDLERINFO * 0x00000000) line 88
CCmdTarget::OnCmdMsg(unsigned int 1004, int 0, void * 0x00000000, AFX_CMDHANDLERINFO * 0x00000000) line 302 + 39 bytes
CDialog::OnCmdMsg(unsigned int 1004, int 0, void * 0x00000000, AFX_CMDHANDLERINFO * 0x00000000) line 97 + 24 bytes
CWnd::OnCommand(unsigned int 1004, long 133210) line 2088
CWnd::OnWndMsg(unsigned int 273, unsigned int 1004, long 133210, long * 0x0012efe0) line 1597 + 28 bytes
CWnd::WindowProc(unsigned int 273, unsigned int 1004, long 133210) line 1585 + 30 bytes
AfxCallWndProc(CWnd * 0x0012f564 {CUpload hWnd=0x00080786}, HWND__ * 0x00080786, unsigned int 273, unsigned int 1004, long 133210) line 215 + 26 bytes
AfxWndProc(HWND__ * 0x00080786, unsigned int 273, unsigned int 1004, long 133210) line 368
AfxWndProcBase(HWND__ * 0x00080786, unsigned int 273, unsigned int 1004, long 133210) line 220 + 21 bytes
USER32! 77d48709()
USER32! 77d487eb()
USER32! 77d4b743()
USER32! 77d4b7ab()
COMCTL32! 773f6ff6()
COMCTL32! 773f70d8()
COMCTL32! 773f93dd()
USER32! 77d48709()
USER32! 77d487eb()
USER32! 77d489a5()
USER32! 77d489e8()
USER32! 77d6e819()
USER32! 77d65ce2()
CWnd::IsDialogMessageA(tagMSG * 0x004b3228 {msg=0x00000202 wp=0x00000000 lp=0x000a0009}) line 182
CWnd::PreTranslateInput(tagMSG * 0x004b3228 {msg=0x00000202 wp=0x00000000 lp=0x000a0009}) line 3424
CDialog::PreTranslateMessage(tagMSG * 0x004b3228 {msg=0x00000202 wp=0x00000000 lp=0x000a0009}) line 92
CWnd::WalkPreTranslateTree(HWND__ * 0x0007028e, tagMSG * 0x004b3228 {msg=0x00000202 wp=0x00000000 lp=0x000a0009}) line 2667 + 18 bytes
CWinThread::PreTranslateMessage(tagMSG * 0x004b3228 {msg=0x00000202 wp=0x00000000 lp=0x000a0009}) line 665 + 18 bytes
CWinThread::PumpMessage() line 841 + 30 bytes
CWnd::RunModalLoop(unsigned long 4) line 3478 + 19 bytes
CDialog::DoModal() line 536 + 12 bytes
CBookMarks::OnUpload() line 494
_AfxDispatchCmdMsg(CCmdTarget * 0x00d32050 {CBookMarks hWnd=0x00040730}, unsigned int 1029, int 0, void (void)* 0x00402540 CBookMarks::OnUpload(void), void * 0x00000000, unsigned int 12, AFX_CMDHANDLERINFO * 0x00000000) line 88
CCmdTarget::OnCmdMsg(unsigned int 1029, int 0, void * 0x00000000, AFX_CMDHANDLERINFO * 0x00000000) line 302 + 39 bytes
CView::OnCmdMsg(unsigned int 1029, int 0, void * 0x00000000, AFX_CMDHANDLERINFO * 0x00000000) line 159 + 24 bytes
CWnd::OnCommand(unsigned int 1029, long 329478) line 2088
CWnd::OnWndMsg(unsigned int 273, unsigned int 1029, long 329478, long * 0x0012f834) line 1597 + 28 bytes
CWnd::WindowProc(unsigned int 273, unsigned int 1029, long 329478) line 1585 + 30 bytes
AfxCallWndProc(CWnd * 0x00d32050 {CBookMarks hWnd=0x00040730}, HWND__ * 0x00040730, unsigned int 273, unsigned int 1029, long 329478) line 215 + 26 bytes
AfxWndProc(HWND__ * 0x00040730, unsigned int 273, unsigned int 1029, long 329478) line 368
AfxWndProcBase(HWND__ * 0x00040730, unsigned int 273, unsigned int 1029, long 329478) line 220 + 21 bytes
USER32! 77d48709()
USER32! 77d487eb()
USER32! 77d4b743()
USER32! 77d4b7ab()
COMCTL32! 773f6ff6()
COMCTL32! 773f70d8()
COMCTL32! 773f93dd()
USER32! 77d48709()
USER32! 77d487eb()
USER32! 77d4c00e()
USER32! 77d4e366()
CWnd::DefWindowProcA(unsigned int 514, unsigned int 0, long 786520) line 1000 + 32 bytes
CWnd::WindowProc(unsigned int 514, unsigned int 0, long 786520) line 1586 + 26 bytes
AfxCallWndProc(CWnd * 0x00d32150 {CButton hWnd=0x00050706}, HWND__ * 0x00050706, unsigned int 514, unsigned int 0, long 786520) line 215 + 26 bytes
AfxWndProc(HWND__ * 0x00050706, unsigned int 514, unsigned int 0, long 786520) line 368
AfxWndProcBase(HWND__ * 0x00050706, unsigned int 514, unsigned int 0, long 786520) line 220 + 21 bytes
USER32! 77d48709()
USER32! 77d487eb()
USER32! 77d489a5()
USER32! 77d489e8()
USER32! 77d6e819()
USER32! 77d65ce2()
CWnd::IsDialogMessageA(tagMSG * 0x004b3228 {msg=0x00000202 wp=0x00000000 lp=0x000a0009}) line 182
CWnd::PreTranslateInput(tagMSG * 0x004b3228 {msg=0x00000202 wp=0x00000000 lp=0x000a0009}) line 3424
CFormView::PreTranslateMessage(tagMSG * 0x004b3228 {msg=0x00000202 wp=0x00000000 lp=0x000a0009}) line 213
CWnd::WalkPreTranslateTree(HWND__ * 0x0007028e, tagMSG * 0x004b3228 {msg=0x00000202 wp=0x00000000 lp=0x000a0009}) line 2667 + 18 bytes
CWinThread::PreTranslateMessage(tagMSG * 0x004b3228 {msg=0x00000202 wp=0x00000000 lp=0x000a0009}) line 665 + 18 bytes
CWinThread::PumpMessage() line 841 + 30 bytes
CWinThread::Run() line 480 + 11 bytes
CWinApp::Run() line 400
AfxWinMain(HINSTANCE__ * 0x00400000, HINSTANCE__ * 0x00000000, char * 0x00151f04, int 1) line 49 + 11 bytes
WinMain(HINSTANCE__ * 0x00400000, HINSTANCE__ * 0x00000000, char * 0x00151f04, int 1) line 30
WinMainCRTStartup() line 330 + 54 bytes
KERNEL32!
And here is a disassembly immediately surrounding the code that execution stops on.
7C80979D lock xadd dword ptr [ecx],eax
Any help regardning this ........
|