Re: List iteration Problem
Paste more code to show where/how rects is coming from.
Re: List iteration Problem
I have a function like below...
CheckRects(RTMPRegion &rgn,rectlist &rects)
{
rectlist::iterator i;
for (i = rects.begin(); i != rects.end(); i++)
{
CaptureScreen(*i, m_mainbuff);
}
}
calling function .........
CheckRects(rgn, rectsToScan);
Now.....
Prototype of CaptureScreen()...
void CaptureScreen(RECT &UpdateArea, BYTE *scrBuff);
And also here when I convert *i like below....
CaptureScreen((RECT &)i, m_mainbuff);
then error does not come but when for loop goes to increment the value of i
then it gives the error like
list iterator is not incremental
Re: List iteration Problem
Quote:
Originally Posted by ashishbhatt12
And also here when I convert *i like below....
CaptureScreen((RECT &)i, m_mainbuff);
You don't need to convert anything.
When you pass a reference, you pass the item. Since *i is a RECT, you pass *i.
Code:
CaptureScreen(*i, m_mainbuff);
Note that this has nothing to do with RECTS. You just need to know what it means when a function takes a reference to an object as a parameter.
Regards,
Paul McKenzie
Re: List iteration Problem
I do not see anything wrong with the code that you have pasted so far. You will have to send in more code to show us where that rectangle list is coming from - how it is created, how it was populated, how it came into being. I suspect that there is something wrong with that list.
Re: List iteration Problem
**************
Sorry,but i don't realy know how to use code tags in this forum
// Get list of rectangles for checking
rectlist rectsToScan;
m_region.Rectangles(rectsToScan);
I use this two lines to get recangles. Here m_region is object of RTMPRegion class in which I am creating recangles.
And here is Rectangles() function......
BOOL RTMPRegion::Rectangles(rectlist &rects)
{
int buffsize;
DWORD x;
RGNDATA *buff;
// If the region is empty then return empty rectangle list
if (region == NULL)
return FALSE;
// Get the size of buffer required
buffsize = GetRegionData(region, NULL, 0);
buff = (RGNDATA *) new BYTE [buffsize];
if (buff == NULL)
return FALSE;
if (GetRegionData(region, buffsize, buff))
{
for (x=0; x<(buff->rdh.nCount); x++)
{
// Obtain the rectangles from the list
RECT *rect = (RECT *) (((BYTE *) buff) + sizeof(RGNDATAHEADER) + x * sizeof(RECT));
rects.push_front(*rect);
}
}
// Delete the temporary buffer
delete [] buff;
return !rects.empty();
//return TRUE;
}
In this class I create rectangles from region and store it into the lilst.
Thanks for taking interest.
Ashish
Re: List iteration Problem
Please edit your post to use code tags. The code you posted is unreadable.
Regards,
Paul McKenzie
Re: List iteration Problem
Is there any multithreading involved, by any chance?
Re: List iteration Problem
There is no any multithreading used in my application in my project.
But, I have used windows Hooks used as dll which runs as other project in workspace and yes on which my main MFC project is dependant.
Thanks.
Re: List iteration Problem
Quote:
Originally Posted by ashishbhatt12
**************
Sorry,but i don't realy know how to use code tags in this forum
When you edit your post, do you see the "Code" icon above the post window?
The code tags use square brackets, not angle brackets.
Regards,
Paul McKenzie
Re: List iteration Problem
Quote:
Originally Posted by ashishbhatt12
**************
// Get list of rectangles for checking
My feeling is that you're doing a lot more in-between when you call this function, and when you're iterating through the list, causing the problem.
Code:
#include <list>
#include <vector>
#include <windows.h>
typedef std::list<RECT> rectlist;
HRGN region;
BOOL Rectangles(rectlist &rects)
{
int buffsize;
DWORD x;
// If the region is empty then return empty rectangle list
if (region == NULL)
return FALSE;
// Get the size of buffer required
buffsize = GetRegionData(region, NULL, 0);
std::vector<RGNDATA> buff( buffsize );
if (GetRegionData(region, buffsize, &buff[0]))
{
for (x=0; x<(buff[0].rdh.nCount); x++)
{
// Obtain the rectangles from the list
RECT *rect = (RECT *) (((BYTE *) &buff[0]) + sizeof(RGNDATAHEADER) + x * sizeof(RECT));
rects.push_front(*rect);
}
}
return !rects.empty();
}
void SomeFunction(RECT& theRect)
{
//
}
int main()
{
rectlist rectsToScan;
Rectangles(rectsToScan);
rectlist::iterator i = rectsToScan.begin();
for (i = rectsToScan.begin(); i != rectsToScan.end(); ++i)
SomeFunction(*i);
}
Here is a compilable, but simple version of what you posted (I used vector instead of new[] and delete[], and I didn't set "region" to anything). Given the above, add whatever needs to be added to get it to do the work.
Now that the code is isolated away from anything else you haven't posted, does the code above work? If it does, then the problem is not iteration -- it is something else in your code that you didn't post that you're doing.
Regards,
Paul McKenzie