Click here to Skip to main content
15,902,114 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: Converting ANSI to UNICODE Pin
Michael Dunn4-Aug-09 22:23
sitebuilderMichael Dunn4-Aug-09 22:23 
GeneralRe: Converting ANSI to UNICODE Pin
bhanu_reddy094-Aug-09 22:34
bhanu_reddy094-Aug-09 22:34 
GeneralRe: Converting ANSI to UNICODE Pin
CPallini4-Aug-09 23:47
mveCPallini4-Aug-09 23:47 
GeneralRe: Converting ANSI to UNICODE Pin
Souldrift4-Aug-09 22:38
Souldrift4-Aug-09 22:38 
GeneralRe: Converting ANSI to UNICODE Pin
bhanu_reddy094-Aug-09 22:42
bhanu_reddy094-Aug-09 22:42 
GeneralRe: Converting ANSI to UNICODE Pin
Souldrift4-Aug-09 23:28
Souldrift4-Aug-09 23:28 
GeneralRe: Converting ANSI to UNICODE Pin
bhanu_85095-Aug-09 2:50
bhanu_85095-Aug-09 2:50 
Question_MailItemPtr Pin
john56324-Aug-09 21:15
john56324-Aug-09 21:15 
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 

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.