Environment VC6.0, Windows 98.
I have a section of code that is throwing a ResourceException, but I can not
quite figure out why. The extract of code is called frequently to draw a
bitmap and a list of annotations. The drawing is repeated approximately once
every 100ms. After running for about 30 seconds the program crashes with an
unhandled resource exception.
Am I doing something bad?
Essentially the steps are:
1) grab an image from the capture card
2) convert the image to a device dependent bitmap.
3) create a memory DC
4) select the DDB into the memory context
5) add a list of annotations to the memory dc
6) bitblt the memory DC to the screen DC.
The resource exception occurs when constructing the CPen or CBrush for one
of the annotations. If I do not create a pen or brush the software does not
There are only 3 annotations in my list at present. The greater the number
of annotations the quicker the software crashes. This seems to suggest that
the system is running out of resource handles? But I believe I am returning
them to the systems at the end of the function call?
Any help would be much appreciated.
Thanks in advance, here is my code:
// Get a Device Dependent Bitmap from the DIB.
HBITMAP handle = GetDDB(bitmap_info, grabbedframe.framebits);
CBitmap* bitmap = CBitmap::FromHandle(handle);
// select the grabbed frame in to a memory device context.
CBitmap* old_bitmap = mem_dc.SelectObject(bitmap);
for (int index = 0; index < annotation_list.GetSize(); index++)
// select the correct pen and brush for drawing the selected
// draw the current annotation.
// draw the bitmap to the screen.
// remove any objects used in the memory dc.
// I have also tried storing the last item returned from SelectObject
here. But I believe this does the same thing.
// free up the bitmap handle.