LoadImages fails after X number of loads on same images
A little background can be found in the link below on what i'm doing.
http://www.microsoft.com/communities/newsgroups/en-us/default.aspx?query=loadimage+fails&dg=microsoft.public.vc.mfc&cat=en_US_f0847235-3112-4b9a-8717-b82f7898eeea&lang=en&cr=US&pt=&catlist=&dglist=&ptlist=&exp=&sloc=en-us
My problem is that after say 20 trys(It's triggered by a button press),
Loadimage has a valid path for a image but it fails to load it. It also
varies. Sometime it will fail every time after that and sometimes it will
work on the next iteration.
Here is the code:
void CWCStatic::SetBitmap(char *imagepath)
{
//CAqtestDlg *asdf=(CAqtestDlg *)this->GetParent();
HANDLE hBmp
=LoadImage(NULL,imagepath,IMAGE_BITMAP,0,0,LR_DEFAULTSIZE|LR_LOADFROMFILE);
if (hBmp == NULL){
AfxMessageBox("setbitmap failed");
AfxMessageBox(imagepath);
//asdf->error("LoadImage");
CHAR szBuf[80];
DWORD dw = GetLastError();
sprintf(szBuf, "loadimage failed: GetLastError returned %u\n",dw);
AfxMessageBox(szBuf);
//return;
}
CStatic::SetBitmap((HBITMAP)hBmp);
}
GetLastError returns 0, so nothing really useful there.
This function only loads a background image. Their is about 20
CBitmapButtons that also use a subclass using this same line "below" to load
the images. All of the Buttons still load fine when this happens.
"HANDLE hBmp
=LoadImage(NULL,imagepath,IMAGE_BITMAP,0,0,LR_DEFAULTSIZE|LR_LOADFROMFILE);"
The OS doesn't seem to be running out of Handles,"Verified through task
manager" so i'm not sure what the issue is.
Any ideas on what going wrong?
Thanks.