Re: BYTE?
From: Carl Daniel [VC++ MVP] (cpdaniel_remove_this_and_nospam_at_mvps.org.nospam)
Date: 03/25/04
- Next message: Ricky_at_36: "Conversion of CString to char[]"
- Previous message: mm: "Error and warning enounctered upgrading C++ project to VS.NET 2003"
- In reply to: newbie: "BYTE?"
- Next in thread: newbie: "Re: BYTE?"
- Reply: newbie: "Re: BYTE?"
- Messages sorted by: [ date ] [ thread ]
Date: Thu, 25 Mar 2004 07:08:01 -0800
newbie wrote:
> I am downloading get request for files. The files are basically the
> header followed by bytes of data. What is the best way to process the
> file, removing the header?
> I was going to use the stl string class. But this gave me trouble.
> The problem is I could remove the header but the left over data in
> the buffer got currupted when i cast it from string to BSTR.
I don't see any use of BSTR in the code you show here. You certainly can't
cast anything from "char *" to "BSTR" since the former is a "narrow" string
(8-but characters) and the latter is a "wide" string (16-bit characters).
> Should I
> use string classes, like stl string. Any help greatly appreciated.
> Code even more.
>
> I was trying to do something like this
//onread of socket
void onread(char *data)
{
//when it is true no longer need to look for header
if(decodeheader == false)
{
buff += data;
int x = buff.find("\r\n\r\n");
if(x < string::npos)
{
int len = buff.length();
/*
char *ptr = new char[len];
buff.copy(ptr,len - x,x);
WriteFile(hfile,(BYTE *) ptr, len - x, &dwBytesWritten,
NULL);
*/
// you don't need to allocate a new buffer
// you do need to account for the \r\n\r\n
// (unless you want those written to the file)
x += 4;
WriteFile(hfile,(BYTE*) buff.c_str()+x, len-x,
&dwBytesWritten, NULL);
decodeheader = true;
return true;
}
}
else
{
WriteFile(hfile,(BYTE*)data, a, &dwBytesWritten, NULL);
}
}
While I did make a couple of changes, I don't see anything in your original
code that would lead to "corruption". You did have a memory leak, but then
it's also clear that you've left oiut some of the code. If you could show a
more complete example of what you're trying to do, and describe "corrupted"
a bit better, it would improve the odds of someone posting a solution to
your dilema.
-cd
- Next message: Ricky_at_36: "Conversion of CString to char[]"
- Previous message: mm: "Error and warning enounctered upgrading C++ project to VS.NET 2003"
- In reply to: newbie: "BYTE?"
- Next in thread: newbie: "Re: BYTE?"
- Reply: newbie: "Re: BYTE?"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|