Results 1 to 5 of 5

Thread: I ve run out of ideas

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Sep 2000
    Location
    England
    Posts
    94

    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.
    "Let's all join forces, rule with an iron hand...and prove to all the world, metal rules the land..."
    -- Judas Priest

    My email is [email protected]

  2. #2
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    Also, why not use memcpy or memmove?
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Sep 2000
    Location
    England
    Posts
    94
    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.
    "Let's all join forces, rule with an iron hand...and prove to all the world, metal rules the land..."
    -- Judas Priest

    My email is [email protected]

  4. #4
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    Of course it overwrites it, that's the point of the function!
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  5. #5
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    a DWORD is 4 BYTEs, if you copy a DWORD at a time you save 75% of the time, the result will be identical.
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width