File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes C / C++ and the fly likes Visual Studio 2010 EXE + 2005 DLL Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Languages » C / C++
Bookmark "Visual Studio 2010 EXE + 2005 DLL" Watch "Visual Studio 2010 EXE + 2005 DLL" New topic

Visual Studio 2010 EXE + 2005 DLL

Christophe Verré

Joined: Nov 24, 2005
Posts: 14688

We are using 4 DLLs built with VS2005 in an application built with VS2010. When calling one of the methods of these libraries, the application crashes. (it may also happen in other methods too, but I haven't tried.). The method we are calling changes a long into a custom string class. Let's call it XString. This class extends std::string. The application seems to crash when XString's destructor (and std::string destructor) is called. I "guess" that the problem comes from the fact that the XString object is instantiated in the 2005 DLL using the 2005 CRT redistributable package, passed to our application, and destroyed in our application using the 2010 CRT. Any ideas on this ? We are about to give up and rebuild all DLLs with VS2010 (we don't want to as it will need more time and more money...).

[My Blog]
All roads lead to JavaRanch
Anthony Aj Williams
Ranch Hand

Joined: Jun 10, 2011
Posts: 57
If your DLL interface includes types that depend on the runtime library, such as std::string or std::vector, then any code that uses the DLL must use the same version of the runtime library as the DLL, in order to ensure that the type structures are the same, and that any dynamic memory is returned to the correct heap.

If you wish your DLL to work with code that uses a different version of the runtime library then you must restrict the types used in the DLL interface to things that are not dependent on the runtime library. e.g. pointers, integers, and simple structs that you have written. You could use BSTRs for passing strings, if plain char* strings are not suitable. You could also use an opaque type passed around by pointer, and have the DLL do all the accesses.

If you cannot change your DLL interface, then you will need to ensure that everything uses the same version of the compiler+runtime.

Author of C++ Concurrency in Action
just::thread C++11 thread library
Just Software Solutions Ltd
15 Carrallack Mews, St Just, Cornwall, TR19 7UL, UK. Company No. 5478976
Christophe Verré

Joined: Nov 24, 2005
Posts: 14688

You're right Anthony. Further research showed us that the 2005 std::string byte length was different from the 2010 version. So an std::string instantiated in a 2005 DLL, and released in a 2010 application, will crash. Thanks for the help. We're going to rebuild the DLL.
I agree. Here's the link:
subject: Visual Studio 2010 EXE + 2005 DLL
It's not a secret anymore!