By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,300 Members | 2,044 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,300 IT Pros & Developers. It's quick & easy.

Having troubles with ostrstream: Borland C++ Builder 1.0

P: n/a
1) I’m using Borland C++ Builder 1.0 (a very old (but still good) version).
2) I have an application EXE calling a DLL.
3) A function in the DLL receives a parameter defined as "ostream &" ,
and writes error messages to this stream using the “<<” operator.
4) The EXE file creates an ostrstream variable and passes this to the
DLL function.
5) After the DLL function has finished, the EXE writes some text to an
output file, followed by the ostrstream which has been “filled” by the
DLL function.
6) There is erratic extraneous characters in the final output string,
which appear to come from some corruption of the output from the DLL
process.
7) Both application and DLL are using memshare.hpp and linked with bcbmm.lib

DLL:
unsigned int process(LPCSTR x, ostream & Messages)
{ ….
errorcode = 44;
Messages << “error code ” << errorcode << endl;
……
return errorcode;
}
EXE:
ostrstream MessageBuffer;
// call the DLL process
if (process(“some data here”, MessageBuffer) != 0)
{debugfile << “*error in process*: “<<MessageBuffer.str()
<< endl;
….}

Result:
*error in process*: error code 44 then-a-selection-of-rubbish-characters

If I pass an ofstream (file) to the DLL process (instead of an
ostrstream) the error code is written directly to the output file with
no extraneous characters.

If I use a specific buffer to initialize the ostrstream, all is OK,
there are no extra characters
e.g. char space[2000];
memset(space, 0x00, sizeof(space));
ostrstream MessageBuffer(space, sizeof(space));

I have also tried creating a temporary output file in the EXE, passing
this to the DLL process, then closing it, re-opening it and reading it
back in with getline() and dumping it back out to the desired output
file – this also works OK with no extraneous characters.

The junk text at the end only appears when I create a default ostrstream
and pass this to the DLL process. It seems the junk comes from the
remainder of the internal string buffer used by the ostrstream.

Any ideas why, or how to prevent it?
Oct 3 '06 #1
Share this Question
Share on Google+
1 Reply


P: n/a
On Tue, 03 Oct 2006 21:07:47 +0200, GeeBee <no**@nowhere.netwrote in
comp.lang.c++:
1) I’m using Borland C++ Builder 1.0 (a very old (but still good) version).
2) I have an application EXE calling a DLL.
[snip]

Stop right there, and get thee to Borland's support groups on the
server nntp://newsgroups.borland.com.

There is no such thing as a DLL in the C++ language, this is all
compiler and Windows specific.

--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://c-faq.com/
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++
http://www.contrib.andrew.cmu.edu/~a...FAQ-acllc.html
Oct 4 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.