Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. copy data from two buffer into one

copy data from two buffer into one

Scheduled Pinned Locked Moved C / C++ / MFC
helpquestion
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • V Offline
    V Offline
    venadder
    wrote on last edited by
    #1

    Hi, I am curious abt shortcuts to copying data from two buffers into one. let's say I have an integer and a buffer of LPVOID type. Now i want to copy these two, int first and then all contents of LPVOId buffer( size known ) into the buffer supplied by the user(LPVOID type). memcpy or memmove will do only wholesale copy, no way to specify from what byte to start. is there any way other then byte by byte copy?? how do u do this kinda thing anyways? any pointers will help, thnx will something like this work mydata is allocated and is of LPVOID type myDataSize is UINT and have correct size( hopefully ) of myData void copy( LPVOID buff, size ) { memmove_s( buffer, size, (LPVOID)&someint, sizeof(int) ); buff += sizeof( int ); memmove_s( buffer, ( size - sizeof( int ) ), myData, myDataSize ); //return the input pointer to original value buff -= sizeof( int ); } //this could be totally laughable thing, but am jsut new to this kinda thing //please excuse me if this code seems ridiculous thnx for help.

    V J 2 Replies Last reply
    0
    • V venadder

      Hi, I am curious abt shortcuts to copying data from two buffers into one. let's say I have an integer and a buffer of LPVOID type. Now i want to copy these two, int first and then all contents of LPVOId buffer( size known ) into the buffer supplied by the user(LPVOID type). memcpy or memmove will do only wholesale copy, no way to specify from what byte to start. is there any way other then byte by byte copy?? how do u do this kinda thing anyways? any pointers will help, thnx will something like this work mydata is allocated and is of LPVOID type myDataSize is UINT and have correct size( hopefully ) of myData void copy( LPVOID buff, size ) { memmove_s( buffer, size, (LPVOID)&someint, sizeof(int) ); buff += sizeof( int ); memmove_s( buffer, ( size - sizeof( int ) ), myData, myDataSize ); //return the input pointer to original value buff -= sizeof( int ); } //this could be totally laughable thing, but am jsut new to this kinda thing //please excuse me if this code seems ridiculous thnx for help.

      V Offline
      V Offline
      venadder
      wrote on last edited by
      #2

      yupp it was ridiculous. VOID does not have size so the compiler does not allow pointer aithemetic on it. Any suggestions please!!!!

      1 Reply Last reply
      0
      • V venadder

        Hi, I am curious abt shortcuts to copying data from two buffers into one. let's say I have an integer and a buffer of LPVOID type. Now i want to copy these two, int first and then all contents of LPVOId buffer( size known ) into the buffer supplied by the user(LPVOID type). memcpy or memmove will do only wholesale copy, no way to specify from what byte to start. is there any way other then byte by byte copy?? how do u do this kinda thing anyways? any pointers will help, thnx will something like this work mydata is allocated and is of LPVOID type myDataSize is UINT and have correct size( hopefully ) of myData void copy( LPVOID buff, size ) { memmove_s( buffer, size, (LPVOID)&someint, sizeof(int) ); buff += sizeof( int ); memmove_s( buffer, ( size - sizeof( int ) ), myData, myDataSize ); //return the input pointer to original value buff -= sizeof( int ); } //this could be totally laughable thing, but am jsut new to this kinda thing //please excuse me if this code seems ridiculous thnx for help.

        J Offline
        J Offline
        Justin Tay
        wrote on last edited by
        #3

        venadder wrote:

        //return the input pointer to original value buff -= sizeof( int );

        You're not returning anything. A pointer is not a reference. A pointer could be used as a reference, in which case you'd need a double pointer to modify buff so the calling function can see a change. Anyway what you are attempting to do is pointless as you are trying to preseve the original value, but the original value passed in by the calling function can't be changed in your function, you are only operating on a stack copy of the pointer value.

        memcpy(buffer, &someint, sizeof(int));
        memcpy(((LPBYTE) buffer) + sizeof(int), myData, myDataSize);

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups