Click here to Skip to main content
15,890,609 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: how to enble menu item in a system menu? Pin
vasu_sri20-Jul-10 22:50
vasu_sri20-Jul-10 22:50 
QuestionGDI+ Pin
john563220-Jul-10 21:26
john563220-Jul-10 21:26 
AnswerRe: GDI+ Pin
john563221-Jul-10 1:36
john563221-Jul-10 1:36 
AnswerRe: GDI+ [modified] Pin
Luc Pattyn21-Jul-10 2:20
sitebuilderLuc Pattyn21-Jul-10 2:20 
Questionchar buffer append Pin
gmallax20-Jul-10 20:22
gmallax20-Jul-10 20:22 
AnswerRe: char buffer append Pin
Code-o-mat20-Jul-10 20:48
Code-o-mat20-Jul-10 20:48 
AnswerRe: char buffer append Pin
Niklas L20-Jul-10 21:50
Niklas L20-Jul-10 21:50 
AnswerRe: char buffer append Pin
Aescleal20-Jul-10 22:19
Aescleal20-Jul-10 22:19 
If you're using C then you're going to have to use such abberations as malloc, free and memcpy. If you're using C++ you can get away with using a vector - it can be used just about anywhere a built in array can be used and doesn't involve memory management. If the two buffers are called buffer_1 and buffer_2 (and they're arrays and not some block of memory bunged on the heap):

std::vector<char> appended_buffer( &buffer_1[ 0 ], &buffer_1[ 40 ] );
appended_buffer.resize( appended_buffer.size() + (&buffer_2[ 50 ] - &buffer_2[ 0 ]) );
std::copy( &buffer_2[ 0 ], &buffer_2[ 50 ], &appended_buffer[ 40 ] );


The big problem with this is you have to know the sizes of the buffers you're copying from. You can get around this by never using raw character buffers and using vectors for everything. If buffer_1 and buffer_2 are vectors:

std::vector<char> appended_buffer( buffer_1.size() + buffer_2.size() );
std::copy( buffer_2.begin(), buffer_2.end(),
	std::copy( buffer_1.begin(), buffer_1.end(), appended_buffer.begin() ) );


The nested copying takes uses the fact that std::copy returns the place (actually it's an iterator) where the second copy has to start - really handy. All this is a lot easier than messing about with manually managing memory. Well, unless you're a masochist.

Cheers,

Ash
QuestionOpenGL, cross-platformity, and general nincompoopery Pin
Asday20-Jul-10 15:17
Asday20-Jul-10 15:17 
AnswerRe: OpenGL, cross-platformity, and general nincompoopery [modified] Pin
Sauro Viti20-Jul-10 21:24
professionalSauro Viti20-Jul-10 21:24 
GeneralRe: OpenGL, cross-platformity, and general nincompoopery Pin
Asday20-Jul-10 23:29
Asday20-Jul-10 23:29 
GeneralRe: OpenGL, cross-platformity, and general nincompoopery Pin
Sauro Viti21-Jul-10 0:06
professionalSauro Viti21-Jul-10 0:06 
GeneralRe: OpenGL, cross-platformity, and general nincompoopery Pin
Asday21-Jul-10 0:30
Asday21-Jul-10 0:30 
GeneralRe: OpenGL, cross-platformity, and general nincompoopery Pin
Sauro Viti21-Jul-10 0:51
professionalSauro Viti21-Jul-10 0:51 
QuestionHow could I pass data from MFC application to .Net user control? Pin
Daniel Tong20-Jul-10 13:23
Daniel Tong20-Jul-10 13:23 
AnswerRe: How could I pass data from MFC application to .Net user control? Pin
Code-o-mat20-Jul-10 20:59
Code-o-mat20-Jul-10 20:59 
GeneralRe: How could I pass data from MFC application to .Net user control? Pin
Daniel Tong21-Jul-10 7:49
Daniel Tong21-Jul-10 7:49 
GeneralRe: How could I pass data from MFC application to .Net user control? Pin
Daniel Tong21-Jul-10 7:52
Daniel Tong21-Jul-10 7:52 
GeneralRe: How could I pass data from MFC application to .Net user control? Pin
Code-o-mat21-Jul-10 8:24
Code-o-mat21-Jul-10 8:24 
Questionhow to add cur resources to any executable by program? Pin
nenfa20-Jul-10 10:34
nenfa20-Jul-10 10:34 
QuestionRe: how to add cur resources to any executable by program? Pin
David Crow20-Jul-10 10:51
David Crow20-Jul-10 10:51 
AnswerRe: how to add cur resources to any executable by program? Pin
nenfa20-Jul-10 16:02
nenfa20-Jul-10 16:02 
GeneralRe: how to add cur resources to any executable by program? Pin
Code-o-mat20-Jul-10 21:09
Code-o-mat20-Jul-10 21:09 
GeneralRe: how to add cur resources to any executable by program? Pin
nenfa20-Jul-10 22:50
nenfa20-Jul-10 22:50 
GeneralRe: how to add cur resources to any executable by program? Pin
Code-o-mat20-Jul-10 22:53
Code-o-mat20-Jul-10 22:53 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.