473,324 Members | 2,268 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,324 software developers and data experts.

istream::good() in a dll

Hi all,

we are trying to port a fairly large c++ library to windows using
Visual Studio.net 2003, and are running into some unexpected problems
with the stream handling. Since our development is more or less
Unix-based, I am afraid I am quite a novice to all Windows - specific
stuff, so please excuse my naive terminology. :-)

In our library, we have a string handling class, which contains the
following piece of code:

inline
std::istream& String::getline(std::istream& s, char delimiter)
throw()
{
static char line_buffer[8192];
s.getline(line_buffer, 8191, delimiter);
set(line_buffer);

return s;
}

If I compile the library as a static .lib, and write a program using the
following code:

int main(int argc, char **argv)
{
std::ifstream f("bla", std::ios::in);
String line;

while (f.good())
{
line.getline(f);
std::cout << line << std::endl;
}

return 0;
}

everything works perfectly. But as soon as I compile the library as a dll,
f.good() does nothing. It always returns true, no matter where in the stream
I am. Leading, of course, to abnormal program termination since it reads one
line past the end. The same happens with f.eof(), f.fail(), or f.bad()

I have been told that strange things might happen if you compile the library
and the executable with different versions of the CRT, but as far as I can
see, both use the same: both compilations set a compiler swith /MD

Anyone got any idea what is happening here? And why it works when using a
static lib but not when using a dll?

Thanks a lot,

Andreas Hildebrandt
Nov 17 '05 #1
3 1711
"Andreas Hildebrandt" <a.***********@handshake.de> wrote in message
news:d0*************@news.t-online.com...
I am afraid I am quite a novice to all Windows - specific
stuff, so please excuse my naive terminology. :-)
Roger that.

In our library, we have a string handling class, which contains the
following piece of code:
...
everything works perfectly. But as soon as I compile the library as a dll,
f.good() does nothing.


What is probably happening is that the execuatble and the DLL are built
against different instances of the runtime. If you want to share runtime
"widgets" across a DLL boundary then the executable and DLL must be built
against the same "flavor" of the DLL BASED runtime. By "flavor" I mean that
you must use the same debug/nodebug and single/multithreaded version in
each.

Regards,
Will
Nov 17 '05 #2
William DePalo [MVP VC++] wrote:
"Andreas Hildebrandt" <a.***********@handshake.de> wrote in message
news:d0*************@news.t-online.com...
I am afraid I am quite a novice to all Windows - specific
stuff, so please excuse my naive terminology. :-)


Roger that.

In our library, we have a string handling class, which contains the
following piece of code:
...
everything works perfectly. But as soon as I compile the library as
a dll, f.good() does nothing.


What is probably happening is that the execuatble and the DLL are
built against different instances of the runtime. If you want to
share runtime "widgets" across a DLL boundary then the executable and
DLL must be built against the same "flavor" of the DLL BASED runtime.
By "flavor" I mean that you must use the same debug/nodebug and
single/multithreaded version in each.


He's already building everything with /MD (he thinks). Must be something
else (unless he's not really building everything with /MD).

-cd
Nov 17 '05 #3
"Carl Daniel [VC++ MVP]" <cp*****************************@mvps.org.nospam >
wrote in message news:eS*************@tk2msftngp13.phx.gbl...
He's already building everything with /MD (he thinks). Must be something
else (unless he's not really building everything with /MD).


My bad.

Andreas: as pennance for not reading your message all the way through <g>,
and if you have checked the settings and _are_ really building with the
proper options, then if you like you can send me a the source to the
function that you are trying to export. I'll try building the DLL and its
executable client here with VS.Net 2003.

Regards,
Will

P.S. You can delete the obvious attempt at obfuscation from my email address
but please don't post it here. I have all the offers for Viagra and Cialis I
could ever want. ;-)
Nov 17 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Thomas Matthews | last post by:
Hi, In some threads, some people mentioned that variable initialization is best performed in an initialization list. Is there a way to initialize a variable from an istream in an...
9
by: John Cho | last post by:
// CHO, JOHN #include<iostream> class fracpri{ int whole; int numer; int denom;
7
by: ragi | last post by:
Short version of my program: ifstream File; File.open("test.txt"); if(!File.good()) return; Func(File); <--cannot convert parametr 1 from 'std::ifstream' to 'std::istream'
3
by: Anne-Marte | last post by:
Hi I simply don't understand how to read a simple file using std::istream. How do I open a file for reading with istream?? Anne-Marte
2
by: tvn007 | last post by:
Please help why this code not compile I would like it to be something like this: istringstream stringstreams(line); stringstreams>>ptrstudent->bypassed>>ptrstudent->name>>ptrstudent->midterm;...
13
by: Peteroid | last post by:
These don't work (I'm using VS C++.NET 2005 Express with clr:/pure syntax): ostream& operator <<( ostream& output, String^ str ) { output << str ; //compile error return output ; } ...
13
by: Gianni Mariani | last post by:
What I would like to do is read bytes from a stream, any number and any time. I would like it to wait until there are any bytes to read. I want the exact same functionality as cstdio's "fread"...
3
by: KWienhold | last post by:
I'm currently writing an application (using Visual Studio 2003 SP1 and C#) that stores files and additional information in a single compound file using IStorage/IStream. Since files in a compound...
7
by: John Salmon | last post by:
I'm working with two libraries, one written in old school C, that returns a very large chunk of data in the form of a C-style, NUL-terminated string. The other written in a more modern C++ is...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.