Click to See Complete Forum and Search --> : CDI+: Image::LoadImage(...)


Orf
May 16th, 2006, 04:37 PM
Hi there.
I use this code (well, something like this...) in my application:

try
{
m_dlgFloor.m_pImage = Image::FromFile( L"C:\NotExistingFile.xxx" );
}
catch(...)
{
AfxMessageBox("error!");
}

...well, I expected to see the error box... Am I wrong?

Thanks for your attention.

golanshahar
May 16th, 2006, 05:54 PM
You are missing one \ in the path string.


Image::FromFile( L"C:\\NotExistingFile.xxx" );


Cheers

Orf
May 17th, 2006, 02:52 AM
Well, ok, I mistyped that... but the point is I expected an exception throwing, and no exception came.

ovidiucucu
May 17th, 2006, 04:43 AM
...well, I expected to see the error box... Am I wrong?
Yeah.
None of GDI+ methods throws exceptions.
To see if Image::FromFile succeeded or failed, call GetLastStatus.

pImage = Image::FromFile(L"c:\\blahblah.jpg");
Status status = pImage->GetLastStatus();
if(Ok != status)
{
// something goes wrong; see Status enum.
}

NOTE: Other GDI+ methods return a Status value and that can be also used to see if succeeded. Otherwise, call GetLastStatus like in example above.

Orf
May 17th, 2006, 05:09 AM
Thanks Ovidiu. (I was almost waiting for you... each time I need help you come and provide it :D )

I remember yesterday I was searchind MSDN about this issue, and I found some documentation talking about exceptions being thrown when the file was'nt found... of course today I can't find that document anymore - the docs I've found state the same things you're saying...
...I don'd know, sometimes MSDN seems non-euclidean space (to say the least...)

Thanks again.

ovidiucucu
May 17th, 2006, 11:48 AM
You are welcome!
I remember yesterday I was searchind MSDN about this issue, and I found some documentation talking about exceptions being thrown when the file was'nt found...
Are you sure that was in GDI+ documentation and not in MFC one? :D
Well, I love exceptions handling, but never completely trust in them, especially in that ugly catch(...). ;)

Orf
May 17th, 2006, 02:38 PM
Well... I really can't remember... and I really can't find it anymore. Same old story, with msdn bookmarks: if you bookmark anything sounds interesting you get an useless mess of favorites. But if you don't bookmark something, you'll certainly need that piece of info...

Apart that, I find the latest version of msdn browser's search feature very, very unuseful - expecially if compared to the older vs6.0 one...