JoeC said:
[..JoeC's program reports access violation..]
I have this;
bits = new BYTE[acc*dwn];
So, we're to assume 'bits' is declared as BYTE*, yes? Do you know if
this allocation succeeds? On some older compilers (not compliant now)
you would get NULL in the pointer instead of an exception when
allocation fails. How big a chunk are you requesting? What's the value
of 'acc*dwn'?
for(int lp =0; lp > (acc*dwn); lp++)
You do? How does it work? I suppose your loop never executes, and you
don't even know it...
Now, here you replace the value of 'bits' with whatever 'flip' returns.
Does it return the same pointer? If not, you've just lost your
allocated memory - that's a memory leak. Not such a huge deal, of
course, but you might consider preserving the pointer and deallocating
it after assigning 'bits' its new value. What is also likely that, if
'flip()' yields NULL, then you just made your pointer point to invalid
memory. As soon as you try accessing it (for reading or for writing),
you're likely to get the access violation.
void bitmap::display(HDC hdc, int ac, int dw){
HDC dc = CreateCompatibleDC(NULL);
HBITMAP hbitmap = CreateDIBSection(dc,&bInfo,
DIB_RGB_COLORS,
&pvBits,NULL,0 );
CopyMemory(pvBits, bits, (acc*dwn));
Well, this function is not known in C++ (It's Windows API or?), so we
don't know how 'bits' is manipulated there, you might consider telling
us those details.
SelectObject(dc, hbitmap);
BitBlt(hdc, ac, dw, 16, 16 ,dc, 0, 0, SRCCOPY);
DeleteDC(dc);
BYTE* bitmap::flip(){
BYTE * temp = new BYTE[acc*dwn];
for (int index=0; index < dwn; index++)
memcpy(&temp[((dwn-1) - index)*acc],
&bits[index*acc], acc);
Unless you somehow fudged up the pointer arithmetic (which at the first
sight doesn't seem that), this should be OK if 'bits' has a valid
pointer value. Does it?
OK, so you get your 'bits' to participate in the 'flipping' and you
assign the result to it. Perhaps not so bad, so the error can be elsewhere.
So, which line causes the access violation? Any of the ones you've posted?
V