SON OF A B****!!!
I was looking through other parts of the code and found the problem somewhere else! As it turns out, that run-time error simply refers to an array index out of bounds error (not quite a divide-by-zero, but )
I don't even know why this only came up when I added list boxes, the array had nothing to do with them.
Anyway, sorry for wasting your time.
I am having some weired situation going on in my VC++ program when I allocate and deallocate memory wihtin the application. Lemme explain the scenario, I am having an applicaiton where I allocate memory to a variable (which are initialized to NULL when the program starts) whenever the user requests and only deallocates it when the user requests the same variable again where I reallocate the memory again. But when I deallocate the memory it is not releasing the whole memory that I have allocated it before.
My program starts with total mem usage of 92596 bytes (At this point I haven't allocated any memory to those variables)
When I allocate memory to the first variable using either GlobalAlloc or VirtualAlloc it increases by 94752 bytes which equals to ~2000bytes
When I deallocate the memory using either GlobalFree or VirtualFree it is deallocating only half of the memory ~1000bytes
Now When I reallocate the memory in the same way as above, it is allocating new 2000bytes.
So, in this way slowly the memory being used by my program is increasing drastically after a while, as I sometimes allocate about 225 variables of ~2000bytes each.
But when I deallocate the memory of the same variables when I am exiting the application it does deallocate ~2000bytes of each variable.
Whenever I check it, it is freeing only half of the allocated size. But it frees the whole allocated memory when I deallocate it at the time of terminating the application, not while 'm running the application.
Ok, I figured out the problem. Once I allocate the memory, I am saving data into the variable by calling another function, in this process I am allocating more memory to another variable to hold a bitmap data, which is not being deallocated later and its piling up.
I have a DefWindowProc() function to catch unhandled messages. This function returns an LRESULT. I have a switch statement and in some cases I call CWnd::DefWindowProc(). So I simply return the result of the call to CWnd::DefWindowProc(). In other cases, I handle the message.
What should the value of LRESULT be when I handle the message?