|
Well, generally you do not create CException -based objects directly, you are supposed to use the AfxThrow*Exception(...) functions, and CException -based objects are only supposed to be caught by pointer (never by copy or reference), and you are always supposed to call the Delete() function on them unless you are going to re-throw them.
So, no, that is not the problem.
Peace!
-=- James If you think it costs a lot to do it right, just wait until you find out how much it costs to do it wrong! Avoid driving a vehicle taller than you and remember that Professional Driver on Closed Course does not mean your Dumb Ass on a Public Road! DeleteFXPFiles & CheckFavorites (Please rate this post!)
|
|
|
|
|
This is only the case if you follow the MFC-style exception usage. When using STL-style exceptions, you generally pass them by const-reference. I probably would have passed this exception by const-reference simply because if you are getting a memory exception, something in your memory is royally screwed (meaning, you shouldn't keep using the heap and expect normal results).
If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week
Zac
|
|
|
|
|
Zac Howland wrote: This is only the case if you follow the MFC-style exception usage.
Yep - That is why I specifically mentioned CException .
Zac Howland wrote: I probably would have passed this exception by const-reference simply because if you are getting a memory exception, something in your memory is royally screwed (meaning, you shouldn't keep using the heap and expect normal results).
Remember that MFC is free to allocate that exception object on another memory area as well, like static and/or global. The special AfxThrow*Exception(...) functions may not just use the "plain" heap to allocate the thrown exception object. And it should always be safe to call Delete() off that pointer (not the delete operator) because the exception object knows if it is heap-based or not.
FWIW, I generally catch other types of exception as const reference as well. You generally do not know what to do with a pointer (should I free it, and if so, how?), and there is that whole "slicing" thing...
Peace!
-=- James If you think it costs a lot to do it right, just wait until you find out how much it costs to do it wrong! Avoid driving a vehicle taller than you and remember that Professional Driver on Closed Course does not mean your Dumb Ass on a Public Road! DeleteFXPFiles & CheckFavorites (Please rate this post!)
|
|
|
|
|
Maybe CMemoryException is too catastrophic error, therefore mentioned actions, which requires heap-allocation, cannot be done? In case of fatal errors, the documentation recommends to finish the application with AfxAbort() .
-- modified at 8:48 Monday 26th June, 2006
|
|
|
|
|
Thank you! You would be suprised how often I see code like this, where coders are so stupid that they do not realize that if you are in an out-of-memory situation, you should not be trying to allocate memory!
Peace!
-=- James If you think it costs a lot to do it right, just wait until you find out how much it costs to do it wrong! Avoid driving a vehicle taller than you and remember that Professional Driver on Closed Course does not mean your Dumb Ass on a Public Road! DeleteFXPFiles & CheckFavorites (Please rate this post!)
|
|
|
|
|
Yeah indeed that can be the exception of exceptions. Theoretical...
Practical, appear more "trivial" memory exceptions like (I wrote INT_MAX just as an example of big number, but hopefully you can get the point)
try
{
char* x = new char[INT_MAX];
}
and no something like
try
{
char* x = new char[3];
}
catch(CMemoryException* e)
{
}
Ovidiu Cucu
Microsoft MVP - Visual C++
|
|
|
|
|
You forgot to call Delete() on that exception pointer.
Peace!
-=- James If you think it costs a lot to do it right, just wait until you find out how much it costs to do it wrong! Avoid driving a vehicle taller than you and remember that Professional Driver on Closed Course does not mean your Dumb Ass on a Public Road! DeleteFXPFiles & CheckFavorites (Please rate this post!)
|
|
|
|
|
I don't see any harmful error there.
Just MB_EXCLAMATION is not a MessageBox flag and that can be observed/fixed (replaced with MB_ICONEXCLAMATION) after the first compilation.
Don't shoot the typist!
Ovidiu Cucu
Microsoft MVP - Visual C++
|
|
|
|
|
|
|
|
You are missing the point of the post. The problem is that if you ever catch that exception, you should never try to handle it in the way that the snippet demonstrates.
There are only two reasons to get that exception (ignore the fact that some developers call AfxThrowMemoryException() for the wrong reasons): [1] A heap request cannot be allocated due to an out of memory condition, and [2] the heap is corrupted and Thinks it is out of memory .
For either case, you probably should not be then trying to allocate memory again.
Peace!
-=- James If you think it costs a lot to do it right, just wait until you find out how much it costs to do it wrong! Avoid driving a vehicle taller than you and remember that Professional Driver on Closed Course does not mean your Dumb Ass on a Public Road! DeleteFXPFiles & CheckFavorites (Please rate this post!)
|
|
|
|
|
Well, sometime happens. Making confusion between heap and stack, we are in a hurry calling others "stupid" then abort (call AfxAbort).
Ovidiu Cucu
Microsoft MVP - Visual C++
|
|
|
|
|
Of course I do...
Peace!
-=- James If you think it costs a lot to do it right, just wait until you find out how much it costs to do it wrong! Avoid driving a vehicle taller than you and remember that Professional Driver on Closed Course does not mean your Dumb Ass on a Public Road! DeleteFXPFiles & CheckFavorites (Please rate this post!)
|
|
|
|
|
I can just see a developer, patting himself on the back with having put together an exception handler and then stress testing to see it invoked and wondering why the messagebox is never displayed.
This is a really good example of not seeing the forest for the trees solution to a problem.
Chris Meech
I am Canadian. [heard in a local bar]
When no one was looking, every single American woman between the ages of 18 and 32 went out and got a tatoo just above their rumpus. [link[^]]
|
|
|
|
|
if we select the folder automatically all the files in the folder should be loaded in the listbox.iam able to select the folder but i don't know how to get the total number of files in folder and how to load this files into listbox,
please help me,
sree.
|
|
|
|
|
if you want to get files or folders if you use ListBox see DlgDirList and use m_ListBox.GetCount()
whitesky
|
|
|
|
|
actually my intension just like winamp application,in winamp we have two option add file or add folder.i write for files and i get a problem when i dealing with folders.
how we select the folder and how to add contentsof that folder to listbox.
thank u,
please help me,urgent .
sree
|
|
|
|
|
here is the sample snippet
CFileFind finder;
BOOL bWorking = finder.FindFile("*.*");
while (bWorking)
{
if (finder.IsDots())
continue;
if (!finder.IsDirectory())
{
bWorking = finder.FindNextFile();
m_ListBox.AddString((LPCTSTR) finder.GetFileName());
}
}
SaRath.
"Do Next Thing..."
My Blog | Understanding State Pattern in C++
|
|
|
|
|
Another way to do the same thing
extern CListBox* pmyListBox;
TCHAR lpszWinPath[MAX_PATH], lpszOldPath[MAX_PATH];
::GetWindowsDirectory(lpszWinPath, MAX_PATH);
::GetCurrentDirectory(MAX_PATH, lpszOldPath);
::SetCurrentDirectory(lpszWinPath);
pmyListBox->ResetContent();
pmyListBox->Dir(DDL_READWRITE|DDL_DIRECTORY, _T("*.*"));
::SetCurrentDirectory(lpszOldPath);
SaRath.
"Do Next Thing..."
My Blog | Understanding State Pattern in C++
|
|
|
|
|
|
first of all i add the files using follwing code
POSITION currPos;
char strFilter[] = { "Mp3 files (*.mp3)|*.mp3|All Files (*.*)|*.*||" };
CFileDialog avi(TRUE, ".mp3",NULL,OFN_ALLOWMULTISELECT | OFN_HIDEREADONLY, strFilter);
char drive[_MAX_DRIVE], middle[_MAX_PATH], filename[_MAX_FNAME], ext[_MAX_EXT];
if(avi.DoModal() == IDOK)
{
currPos = avi.GetStartPosition();
while(currPos != NULL)
{
m_SongName = avi.GetNextPathName(currPos);
_splitpath (m_SongName, drive, middle, filename, ext);
m_list7.AddString(m_SongName);
so tell atleast what modufication i should do to ad folder
|
|
|
|
|
|
ok!
how we use SHBrowseFolder it,
i know iam disturbing u,
really sorry,
but my work demands me please,
beacuse it is urgent,
sree.
|
|
|
|
|
sree_as wrote: how we use SHBrowseFolder it,
CString csFolderSelected;
BROWSEINFO bi = {0};
bi.ulFlags = BIF_RETURNONLYFSDIRS ;
LPITEMIDLIST pIt;
if( (pIt = SHBrowseForFolder( &bi )))
{
TCHAR tcPath[ MAX_PATH ];
if( SHGetPathFromIDList( pIt, tcPath ))
{
csFolderSelected = tcPath;
AfxMessageBox( "the user selected the folder " + csFolderSelected );
}
}
nave
|
|
|
|