Having troubles with ostrstream: Borland C++ Builder 1.0

G

GeeBee

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?
 
J

Jack Klein

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,954
Messages
2,570,116
Members
46,704
Latest member
BernadineF

Latest Threads

Top