Click here to Skip to main content
15,888,521 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: _MailItemPtr Pin
Souldrift4-Aug-09 23:57
Souldrift4-Aug-09 23:57 
Questionmemcpy and buffer concatenation Pin
Madhu_Rani4-Aug-09 21:10
Madhu_Rani4-Aug-09 21:10 
AnswerRe: memcpy and buffer concatenation Pin
CPallini4-Aug-09 21:20
mveCPallini4-Aug-09 21:20 
GeneralRe: memcpy and buffer concatenation Pin
Madhu_Rani4-Aug-09 21:39
Madhu_Rani4-Aug-09 21:39 
GeneralRe: memcpy and buffer concatenation Pin
CPallini4-Aug-09 21:54
mveCPallini4-Aug-09 21:54 
AnswerRe: memcpy and buffer concatenation Pin
«_Superman_»4-Aug-09 21:22
professional«_Superman_»4-Aug-09 21:22 
GeneralRe: memcpy and buffer concatenation Pin
Madhu_Rani4-Aug-09 21:33
Madhu_Rani4-Aug-09 21:33 
AnswerRe: memcpy and buffer concatenation Pin
Rajesh R Subramanian5-Aug-09 1:17
professionalRajesh R Subramanian5-Aug-09 1:17 
Hello,

How are you knowing how many bytes are to be read? I've seen most people throw some random and huge number at it. You might want to try IOCtl with FIONREAD this if you aren't doing it already there:

DWORD dwHowMuch = 0;
IOCtl(FIONREAD, &dwHowMuch); //After this call, <code>dwHowMuch</code> will tell you how many bytes should be read with the Receive call.
Receive(m_szBuffer.GetBuffer(dwHowMuch), /*other params*/);
szBuffer.ReleaseBuffer(-1); 

//Now, szBuffer has the data received from the socket.

Note that I'm letting CString do the gruesome stuff of memory allocation and deallocation for me (because CString already has a GetBuffer() method, and I can exploit that here). I'm not proposing this as an excellent solution, but it works and you will be free of any hand-crafted memory management that you might want to implement. I, for once, believe that CString will manage the memory much better than we do (OK, we can write something better, but what the heck... OOP is about reusability and what GetBuffer() has to offer has been good enough for me).

Also note that passing a number to CString::GetBuffer() will dynamically 'adjust' the string buffer to hold at least "that much" bytes that was passed to it (mind you this does not include the terminating zero character, but here, we aren't dealing with a string anyways). This will ensure you won't run out of memory and if the previously allocated memory was good enough to hold the data to be currently received, no harm is done!

I assumed that you're using MFC, but if you are not, I see your query is already answered. Also, note that you don't 'need' MFC as such if you want to just use CString.


It is a crappy thing, but it's life -^ Carlo Pallini

Questionavi cap wrapper frame grabber Pin
vvlnkishore4-Aug-09 20:47
vvlnkishore4-Aug-09 20:47 
AnswerRe: avi cap wrapper frame grabber Pin
Randor 5-Aug-09 16:01
professional Randor 5-Aug-09 16:01 
GeneralRe: avi cap wrapper frame grabber Pin
vvlnkishore5-Aug-09 23:08
vvlnkishore5-Aug-09 23:08 
QuestionHello question about hooking function by using irregualar jumps like ret/push Pin
nah13374-Aug-09 20:29
nah13374-Aug-09 20:29 
QuestionCObject.. Pin
p_19604-Aug-09 20:11
p_19604-Aug-09 20:11 
AnswerRe: CObject.. Pin
CPallini4-Aug-09 21:00
mveCPallini4-Aug-09 21:00 
QuestionOutlook Pin
john56324-Aug-09 20:04
john56324-Aug-09 20:04 
QuestionWriteAllBytes..... Pin
lsh486love4-Aug-09 19:39
lsh486love4-Aug-09 19:39 
AnswerRe: WriteAllBytes..... Pin
«_Superman_»4-Aug-09 19:51
professional«_Superman_»4-Aug-09 19:51 
AnswerRe: WriteAllBytes..... Pin
_AnsHUMAN_ 4-Aug-09 19:53
_AnsHUMAN_ 4-Aug-09 19:53 
QuestionDLL Pin
p_19604-Aug-09 19:07
p_19604-Aug-09 19:07 
AnswerRe: DLL Pin
_AnsHUMAN_ 4-Aug-09 19:26
_AnsHUMAN_ 4-Aug-09 19:26 
AnswerRe: DLL Pin
Rajesh R Subramanian4-Aug-09 19:29
professionalRajesh R Subramanian4-Aug-09 19:29 
Questionping .. Pin
thangvel4-Aug-09 16:02
thangvel4-Aug-09 16:02 
AnswerRe: ping .. Pin
«_Superman_»4-Aug-09 18:31
professional«_Superman_»4-Aug-09 18:31 
QuestionRe: ping .. Pin
David Crow5-Aug-09 3:05
David Crow5-Aug-09 3:05 
AnswerRe: ping .. Pin
KarstenK5-Aug-09 3:41
mveKarstenK5-Aug-09 3:41 

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.