// JP opened flex table

Click to See Complete Forum and Search --> : SHLoadImageFile Problem


ninjascutoffheads
July 9th, 2007, 01:49 PM
Currently I am making a program that can open several images(bmp,jpg) and run them in a slideshow for my treo 700w (Windows Mobile 5.0 Pocket PC). I use SHLoadImageFile to open the images. I have no problems opening as many images as I went when I run them on the treo emulator that I run from VS. But when I try to run it on my phone, it only allows to open three images then just stops letting me load anything else after I try to load the 4th image. I have tried a lot of different things to figure this out but its really hard to debug something that works fine on your computer like that. Here is what I am trying. GetOpenFileName doesn't return an error. SHLoadImageFile doesn't return an error but it doesn't display the Error message box either. I tried inserting message boxes in several places so I could get an idea of where it stops and it stops when it tries temp = SHLoadImageFile line then nothing executes below it. I don't know if there is a limited number of times you can call that function but any help would be very much appreciated.

if (GetOpenFileName(&ofn))
{
//Loads file into an array.
HBITMAP temp;
if((temp = SHLoadImageFile(ofn.lpstrFile))!=NULL) //Only gets to here after 3rd image
{
g_hBitmap[count] = temp;
MessageBox(NULL, ofn.lpstrFile, TEXT("File Loaded Successfully"), MB_OK);
if(count > 0){ index=count;}
count++;
}
else
{
MessageBox(NULL, TEXT("Image Unable to Load"), TEXT("ERROR"), MB_OK);
}
}
else
{
DWORD dw = GetLastError();
if (dw == ERROR_OUTOFMEMORY)
{
MessageBox(NULL, TEXT("Out of Memory"), TEXT("ERROR"), MB_OK);
}
else
{
MessageBox(NULL, TEXT("File Unable to Load"), TEXT("ERROR"), MB_OK);
}
}

Marc G
July 10th, 2007, 01:43 PM
Are the bitmaps you're loading big? You never free the return HBITMAP handle.

ninjascutoffheads
July 10th, 2007, 05:48 PM
They are around 13k per file. I reuse the bitmaps since the slideshow runs continuously so I only free them after I have removed them from the slideshow completely.

VladimirF
July 10th, 2007, 06:26 PM
This might be a stupid question, but is your image #4 OK? Can you load it if it was first?

ninjascutoffheads
July 10th, 2007, 06:54 PM
Ya I have like 12 images and as long as I choose them as one of the first three they work.

VladimirF
July 10th, 2007, 07:17 PM
So you are saying that it never returns fro the call to SHLoadImageFile()?
Is there some remote debugging option?
Generally it's not a good idea to create MessageBox in OutOfMemory condition - you might not have memory for that box either...
How much memory do you have on that phone? Is ther anything else running? 13K images do not look too big...
Just for the test, could you use 1K images? Do you get any further that #3?
What else do you do in your app? Can you create a test app that ONLY loads few images and does nothing else? Would it have the same limits?

ninjascutoffheads
July 10th, 2007, 07:56 PM
When I try to open the 4th image it exits the case statement its under. I can't really think of any remote debugging option that I could do from my phone. But I didn't think about that message box thing that's a good point. But actually if i try to load the 4th image again than i get my file unable to load error message box. I did some further checking and found that it actually completely exits out of my WindowsProc completely after it tries to call SHLoadImageFile and if I run it again to get the error and i call getlasterror on it (which i'm not actually sure works on it) but it didn't come up with out of memory. I get the same result with 1k files and i have about 10 Mb of program memory left on my phone and 50 Mb of storage memory. My application can open an image, display an image, remove an image, run a slideshow and and stop the slideshow.

VladimirF
July 10th, 2007, 08:41 PM
I guess I'd like to see the answer to the rest of my questions:
Can you create a test app that ONLY loads few images and does nothing else? Would it have the same limits?
I can't imagine that your phone would have a limit of 3 GDI handles! Or do you use a lot more in other places?

ninjascutoffheads
July 10th, 2007, 11:46 PM
That's what I'm saying but I'll work on a test app and let you know what happens as soon as I get a chance though.

DDfish
October 4th, 2007, 03:05 AM
It might be possibile to check several things:
1. The memory requireed by SHloadimagefile depends on the picture resolution. For example, if you have 200K jpeg file, but this resolution of this file is 2M. After you call this API, it will consume almost 4M program ram on your device. So, you need to check the resolution of your file and make sure it is not too big.
2. You could try to call DeleteObj after SHloadimagefile. Will it have the same situation ?

//JP added flex table