-
I ve run out of ideas
Hey guys
I have just about run out of ideasi have this piece of code below which is ment to copy one buffer to another.
Code:
void CMiscFunctions::CopyValueToBuffer(BYTE *pDataToCopy, BYTE *pBuffer, DWORD *dwLengthOfBuffer, DWORD dwSizeOfData)
{
DWORD i = *dwLengthOfBuffer;
DWORD y;
char sTest[10];
_ultoa(*dwLengthOfBuffer ,sTest, 10);
AfxMessageBox(sTest);
char sTest2[10];
_ultoa(i ,sTest2, 10);
AfxMessageBox(sTest2);
for(y = 0; y < dwSizeOfData; y++, i++)
{
pBuffer[i] = pDataToCopy[y];
if(y == 0x00000ED85)
{
AfxMessageBox("full");
break;
}
}
*dwLengthOfBuffer = i;
}
But it won't copy anything bigger then 59kb. I posted this before but didn't explain it very well basically it copies from pDataToCopy to pBuffer. i is the position to start copying data to in the pBuffer and y is 0 just to increment through the pDataToCopy buffer. I also put in an if statment to see what the largest value is before it crashes which is 0x00000ED85 in hex or 60805. Which seems like a very odd number to crash on to me.
Anyway all help is appreciated peter.
-
Also, why not use memcpy or memmove? :D
-
2 pointer's to BYTE buffer get passed into the function along with the size of the second buffer being passed in which is the one being copied. The other bit that is past in is a dword containing the value of where to start copying the data to in teh pBuffer.
In answer to your question parksie i don't use mecpy and memmove because the pBuffer is a buffer that contains DWORDS as well and memcpy over writes DWORDS it has written in as soon as you copy in a BYTE, CHAR or any other buffer except DWORD.
-
Of course it overwrites it, that's the point of the function!
-
a DWORD is 4 BYTEs, if you copy a DWORD at a time you save 75% of the time, the result will be identical.