|
See here.
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
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 ........
|
|
|
|
|
Isn't your question the same as [This^]
kiranin wrote: m_strloc = oFileDlg.GetPathName();
Use a CString variable here, instead of that member variable
|
|
|
|
|
I already tried it but i got same problem...
|
|
|
|
|
CString str;<br />
<br />
static TCHAR BASED_CODE szFilter[] = "Windows Setup file (*.pdf;*.xml)|*.pdf;*.xml||";<br />
<br />
CFileDialog oFileDlg(TRUE,"pdf","",OFN_FILEMUSTEXIST|OFN_NOCHANGEDIR, szFilter);<br />
oFileDlg.m_ofn.lpstrTitle = "Select the Installable Application";<br />
<br />
<br />
if(oFileDlg.DoModal() == IDOK)<br />
{<br />
str = oFileDlg.GetPathName();<br />
<br />
AfxMessageBox(str);<br />
}
This should work fine.
|
|
|
|
|
No it is also getting the same problem after displaying in message box
|
|
|
|
|
Is there any thing else you have kept after the message box? If not there has to be no problem at all.
Nobody can give you wiser advice than yourself. - Cicero
|
|
|
|
|
nothing else after messageBox
|
|
|
|
|
It has to do with how you've defined _WIN32_WINNT , most likely as 0x0500 . The OPENFILENAME structure used by CFileDialog is the smaller sized one. So, use GetOpenFileName() instead.
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
i cant understand what u said
i defined _WIN32_WINNT like follwing
#define _WIN32_WINNT 0x500
|
|
|
|
|
kiranin wrote: i cant understand what u said
Which part are you not understanding?
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
Thanks David i got solved by using GetOpenFileName().
|
|
|
|
|
Hi,
Which method of CMenu should I use to find which menu item has been selcted from TrackPopMenu that floating popup menu?
This menu is contextspecific menu activated with right button click.
Thanks
Prithaa
|
|
|
|
|
Im sorry but I dont understand what do you need
|
|
|
|
|
Hi,
Sorry if the question was not clear
I have a menu which is activated in a window with right mouse button click.When the menu appears the user selects a menu option .I want to find out which menu option has been selected from the menu.
Prithaa
|
|
|
|
|
Hello,
all menu items have an identifier, you must to use them to find which menu item has been klicked!
Is that what you mean?
regards
break;
|
|
|
|
|
If you pass the TPM_RETURNCMD flag to TrackPopupMenu() , then the return value indicates what was selected. If you don't use that flag, your window will get a WM_COMMAND message just as if the menu bar had been used.
|
|
|
|
|
Hi,
thanks
I got What has to be done
Prithaa
|
|
|
|
|
If I only know the DIO device is at port 280.
How can I access it? (read / write the pins)
NO API is available.
Please help!
Any relative information is welcome.
Thanks!
|
|
|
|
|
Assuming you're running some windows environment, you'll need a device driver for your device. You're not allowed to access the hardware from user mode.
Since you clearly state that "NO API is available", I assume you don't have a driver for your device and you've possibly made the device yourself.
If you bought the device it should be shipped with a device driver, unless it registers itself as a common device such as a COM port, in which case you can use ::CreateFile(), ::ReadFile(), ::WriteFile(), ::CloseHandle() and such to access it.
If you don't know anything else about the device besides the I/O port: give it up, there's no way to guess.
However, if you know how the device works and how to communicate with it at low level, you can develop a device driver of your own.
This way is quite hard, but if you'd like to have a go for it, start by reading Toby Opfermans article serie about device driver development here[^].
Hope this helps
--
Roger
"It's supposed to be hard, otherwise anybody could do it!" - selfquote
"No one remembers a coward!" - Jan Elfström 1998 "...but everyone remembers an idiot!" - my lawyer 2005 when heard of Jan's saying above
|
|
|
|
|
The device is together with the PC on delivery.
And it works in the debug mode.
eg. type "-o 280 F1" as a command
I just dont know how to access it using cpp.
So, I think I can use ::CreateFile(), ::ReadFile(), ::WriteFile(), ::CloseHandle() to access it, right?
More question, using ::CreateFile, should I use "port280" as the file name?
Thanks very much!
|
|
|
|
|
Archyami wrote: just dont know how to access it using cpp.
So, I think I can use ::CreateFile(), ::ReadFile(), ::WriteFile(), ::CloseHandle() to access it, right?
More question, using ::CreateFile, should I use "port280" as the file name?
If you open a device with ::CreateFile(), you have to provide the device name as argument to the function, e.g. "COM1" when opening communications port 1.
You have to find out what your device is called before you can access it through these methods. Look for settings in the Device Manager.
It's not possible for anyone else to know what your device is called in your machine. Perhaps if you mentioned what kind of device it is someone could tell you how the device usually presents itself and how to communicate with it.
--
Roger
"It's supposed to be hard, otherwise anybody could do it!" - selfquote
"No one remembers a coward!" - Jan Elfström 1998 "...but everyone remembers an idiot!" - my lawyer 2005 when heard of Jan's saying above
|
|
|
|
|
Hi,
I'd like to save the Z order of all windows. In fact, i'm working on a HideAll windows and ShowAll.
That's why i'd like to save this z-order to get the windows restaured in the same order.
thanks
|
|
|
|
|
|
ENumWindows and store the Window Handle in the array!
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
Support CRY- Child Relief And You
|
|
|
|
|