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