different crt's in dll and calling app 
Author Message
 different crt's in dll and calling app

Hi

I need some more insight on what happens if a dll is linked
against a particular crt and the calling app against another.

From what I understand from msdn, both the dll and the app must
be linked against the same crt (for example debug static multithreaded)

But imho, this is not enough. I think they must even both be
dynamically linked crt's. My arguing is if they're not, you have
two different heaps which aren't compatible.

Well
feel free to reply

Rene

Sent via Deja.com http://www.*-*-*.com/
Before you buy.



Tue, 25 Feb 2003 21:53:54 GMT  
 different crt's in dll and calling app

Rene,

Quote:
> I need some more insight on what happens if a dll is linked
> against a particular crt and the calling app against another.

> From what I understand from msdn, both the dll and the app must
> be linked against the same crt (for example debug static multithreaded)

Not so. This is the case with static libs, but not with Dlls. However, you
should be aware of the limitations involved when they don't link with the
same CRT.
In other words, be aware of the following limitations if they are not:
- Don't allocate memory in one module and free it in another (which, imho,
it's bad design anyway)
- Make sure you deal with threading issues correctly, i.e. synchronize calls
to the dll if it's not thread safe

Quote:

> But imho, this is not enough. I think they must even both be
> dynamically linked crt's. My arguing is if they're not, you have
> two different heaps which aren't compatible.

Not a real problem, as far as I'm concerned, if you design your app
correctly. Remember that the whole point of dlls is code reuse and
modularity. You don't have a choice when it comes to third party libraries,
usually.

--
Tomas Restrepo [VC++ MVP]
http://www.mvps.org/windev



Tue, 25 Feb 2003 23:42:20 GMT  
 different crt's in dll and calling app

Quote:
> Rene,
> > I need some more insight on what happens if a dll is linked
> > against a particular crt and the calling app against another.

> > From what I understand from msdn, both the dll and the app must
> > be linked against the same crt (for example debug static multithreaded)

> Not so. This is the case with static libs, but not with Dlls. However, you
> should be aware of the limitations involved when they don't link with the
> same CRT.
> In other words, be aware of the following limitations if they are not:
> - Don't allocate memory in one module and free it in another (which, imho,
> it's bad design anyway)

I fully support your last point. But the reason I dug into
that was because I had/have a dll which exposes a class method
that returns a std::string. The app crashed when the returned
std::string went out of scope (i.e. when it was deallocated)
I assume this happens because std::string is clever enough to
lazily copy its content (copy on write).

Rene

Sent via Deja.com http://www.deja.com/
Before you buy.



Wed, 26 Feb 2003 06:32:09 GMT  
 different crt's in dll and calling app
Rene,

Quote:
> I fully support your last point. But the reason I dug into
> that was because I had/have a dll which exposes a class method
> that returns a std::string. The app crashed when the returned
> std::string went out of scope (i.e. when it was deallocated)
> I assume this happens because std::string is clever enough to
> lazily copy its content (copy on write).

That's an important point. Allow me to be the one to tell you that the VC++
6.0 implementation of std::string has several other problems relating to
that particular feature (some of which have been fixed in more recent
editions of the Dinkumware library, I understand)

P.S. Doug Harrison (Hi Doug!) is more well versed on the matter, though, so
hopefully he will share some of his wisdom in the matter with us :)

--
Tomas Restrepo [VC++ MVP]
http://www.mvps.org/windev



Wed, 26 Feb 2003 10:35:10 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. Dynamic CRT EXE + static CRT DLL + Dinkumware

2. What's different between MFC App and MFC App as NTService

3. DLL calling EXE's app/view/frm functions

4. VC6 DLL calls VB6 DLL calls back to VC6 DLL: Occasional GPF or ‘Bad DLL calling convention'

5. Exporting string from dll using non DLL version of CRT

6. Help - Calling ActiveX DLL function from VB and C++ returns different values

7. How to share MFC class in memory in DLL that is called by different application

8. calling Watcom DLL's form other compilers EXE's

9. Dll's with different names for debug-/release-Version

10. Same EVC + Different PC's = arm exe DIFFERENT file size (iPAQ)

11. List all CRT calls in a file

12. Debugging app that calls ExitWindowsEx doesn't work

 

 
Powered by phpBB® Forum Software