|
|
What about a simple way like that: Check for the size of the buffer return, if it is as big as your buffer, read the socket again and append it at the end of the buffer, keep doing that until the size returned is smaller than your buffer. That's the end of the packet!
Take a look at the code below:
unsigned char *BigBuff = NULL;
unsigned char buf[4096];
ULONG size = 4096;
ULONG rc = 0;
BOOL bMoreData = false;
ULONG TotalSize = 0;
do
{
bMoreData = true;
memset(&buf[0], 0, 4096);
rc = TcpRecv(SocAccepted, buf, size);
if ( rc == 0 )
{
goto end;
}
if ( rc == (ULONG)SOCKET_ERROR )
goto end;
TotalSize = TotalSize + rc;
if ( BigBuff == NULL )
{
BigBuff = (unsigned char *) malloc (rc+10);
if ( !BigBuff )
return NULL;
memcpy(BigBuff, buf, rc);
}
else
{
unsigned char *p = NULL;
p = (unsigned char *)realloc(BigBuff, TotalSize);
if ( !p )
{
free( BigBuff );
return NULL;
}
BigBuff = p;
memcpy(&BigBuff[TotalSize-rc], buf, rc);
}
if ( rc == size )
bMoreData = true;
}while(bMoreData);
end:
return (&BigBuff[0]);
|
|
|
|
|
Hi,
I am reading some books on C++ and MFC. It seems to me that without a solid understanding of C/C++ compiler, mastering C++ and MFC is a mission imposible. For example, CRuntimeClass, Message Map and RTTI etc. Any information on how and where to get materials on C/C++ compiler is greatly appreciated.
Thank you in advance.
Best regard.
I confess that I am a stubborn guy, but why not put things thoroughly, logically and systematically clean. One concrete prolem is worth a thousand unapplied abstractions.
|
|
|
|
|
NicholasCougar wrote:
Any information on how and where to get materials on C/C++ compiler
Your best bet is a good text on compiler theory. I used the Dragon Book in college in 1984, but the same principles still apply today.
/ravi
"There is always one more bug..."
http://www.ravib.com
ravib@ravib.com
|
|
|
|
|
NicholasCougar wrote:
For example, CRuntimeClass, Message Map and RTTI etc.
Heck, I must be in trouble - I've been programming C++ since late 92 and I've never needed to know how CRuntimeClass and RTTI work.
You can learn more about MFC in the book MFC Internals.
Michael
|
|
|
|
|
I try to measure the dimension for a text say "Hello".
I set mapping mode to MM_LOENGLISH.
CFont font;
font.CreatePointFont(360,"Verdana");
pDC->SelectObject(&font);
CSize sz = pDC->GetTextExtent("Hello");
the width sz.cx (1.19 inch) seems ok in real printing. But sz.cy (0.57inch) is greater than the actual (0.344inch) in printout. Can anyone tell me how to calculate the real height???
|
|
|
|
|
I believe that when windows calculates the height of characters it includes the height of the ascending and descending line of the font, not just the height of the character that you see. I am not 100% certain of this, but one way that you could test this is by calling getTextExtent on 5 different characters, and I believe the same height should come back for all of the characters.
Build a man a fire, and he will be warm for a day Light a man on fire, and he will be warm for the rest of his life!
|
|
|
|
|
look up the font metrics stuff in msdn
there are all sorts of bits and pieces added together to get the bounding 'box' of text ... leading, ascenders, descenders, etc
all fun stuff if you have nothing else to do
---
situations to avoid #37: "good morning ... how many sugars do you take in your coffee ... and what was your name again?"
|
|
|
|
|
Hello all -
I don't know if this is a limitation of the library or if it's just my computer. I can make 16 sucessfull calls to this function, and i get back a valid timer id, and the callback function i specify is called. After the 16th, it fails.
I should be clearer...i can Queue up 16 of them. if i try to call this 17 times before the 1st callback is fired, the 17th call fails. Anyone know if this is a limitation of the library - or just my computer?
Marcus Spitzmiller
"Ha ha, Stupid bloropope.." - Homer
|
|
|
|
|
This has been spammed here before, and the general consensus was that not only was this not a terribly compelling app, but it's offensive that you post your ads in the forums when there is a facility provided for people to buy advertising on the site if they want it.
Christian
The tragedy of cyberspace - that so much can travel so far, and yet mean so little.
"But there isn't a whole lot out there that pisses me off more than someone leaving my code looking like they leaned on the keyboard and prayed that it would compile.
- Jamie Hale, 17/4/2002
|
|
|
|
|
CRichEditCtrl wants me to set the fontsize in twips, whatever that is. How can I set the font to something like Verdana 9.
Sprudling
|
|
|
|
|
|
Thanks, this was exactly what I wanted
Sprudling
|
|
|
|
|
CFont font;
font.CreatePointFont(90,"Verdana");
richctrl.SetFont(&font);
|
|
|
|
|
1440 twips = 1 inch
hmmmm ... wonder why guys don't use the twip measuring system more often?
---
situations to avoid #37: "good morning ... how many sugars do you take in your coffee ... and what was your name again?"
|
|
|
|
|
I want the text in a CRichEditCtrl to appear as in a console, with the "latest" line at the bottom and all text bottomaligned, so that if there is just one line it'll be alone at the bottom. Is there a way of implementing this...?
Sprudling
|
|
|
|
|
You can use CRichEditCtrl::SetRect(). Apply the number of lines, the font height and some math.
|
|
|
|
|
Or might want to try CRichEditCtrl::SetParaFormat
|
|
|
|
|
How could CRichEditCtrl::SetParaFormat help me?
Sprudling
|
|
|
|
|
Thanks; how to calculate a font's height?
And what if I've turned on wrapping (no horizontal scoll). Will that count as a new line or not? (When returned from CRichEditCtrl::GetLineCount())
Sprudling
|
|
|
|
|
The height can be calculated using CDC::GetTextExtent(). As for the wrapping, I have no clue You will have to try it.
|
|
|
|
|
Niklas Lindquist wrote:
The height can be calculated using CDC::GetTextExtent().
or rather use the lfHeight member of the LOGFONT structure. Can be retreived from CFont::GetLogFont() I think.
|
|
|
|
|
Hi,
I insert a resource script into my Win32 Application and create a menu named "menu01", when run the project, no menu appear but an empty window.
What's wrong?
By the way, I want know how to add color and format my codes for better readability.
Best regard.
I confess that I am a stubborn guy, but why not put things thoroughly, logically and systematically clean. One concrete prolem is worth a thousand unapplied abstractions.
|
|
|
|
|
NicholasCougar wrote:
I insert a resource script into my Win32 Application and create a menu named "menu01", when run the project, no menu appear but an empty window.
What's wrong?
If I am not mistaken, you cannot add a menu to the console window through regular application means. It is mainly for stdout and stdin. If you want menus and things like that why don't you create a WIN32 application with the user interface elements. It is also possible to redirect stdout and stdin windows components if this is what you need.
NicholasCougar wrote:
By the way, I want know how to add color and format my codes for better readability.
I am unclear what you are asking here. Do you want your source code in the editor to be syntax highlighted, or the codes in your program window? What editor are you using for your code?
Build a man a fire, and he will be warm for a day Light a man on fire, and he will be warm for the rest of his life!
|
|
|
|
|
Please have a look at your post, it's very neaty and readable, for you use small font, hightlight, and italic. In the message box where I currently typing words in, no such this like small font, italic etc. I want use them in my post here for better readability.
Thank you.
Best regard.
I confess that I am a stubborn guy, but why not put things thoroughly, logically and systematically clean. One concrete prolem is worth a thousand unapplied abstractions.
|
|
|
|