I have to create BYTE* array that will store some text and binary data for Http request.
Something like:
Content-Type: multipart/form-data; boundary=Asrf456BGe4h
--Asrf456BGe4h
Content-Disposition: form-data; name="DestAddress"
...
--Asrf456BGe4h
Content-Disposition: form-data; name="AttachedFile1"; filename="photo.jpg"
Content-Type: image/jpeg
...binary data...
I’m afraid to use standard atl strings ’cause they truncate my binary files. How would you concatenate such things? I’d like to program like that:
DynamicArray arr();
arr.Add("Content-Type ... ");
arr.Add(imgContent, imgContentSize);
arr.Add("Content-Type...");
BYTE* buf;
arr.GetBits(buf);
Finally I should have BYTE* array. What ATL classes should provide me such functionality?
First, you can put raw data into an
std::stringwith no risk of any problems occurring. It may confuse the reader, who expectsstd::stringto contain text, but in specific cases (and inserting raw data into an HTTP response could be a valid example), it is justified.For the second, I’m not sure what you mean by “truncate my binary files”. If the file is written and read in binary mode, there should be no problem; there certainly isn’t on the systems I’m familiar with (Unix and Windows).
Finally, while I’m not sure how
BYTEis defined (probably—or at least hopefully—, it’sunsigned char). In that case, the simplest solution is probably to use anstd::vector<BYTE>to build up the buffer. To append a string to it:(The implicit conversion of
chartounsigned chardoes the trick here.)