Groups | Blog | Home
all groups > visual c libraries > july 2003 >

visual c libraries : Can't link VC6 dll using std with VC .net main()


stephane jaeger
7/7/2003 6:55:01 PM
Hi,
I am currently having trouble with the following code sample:

#include "stdafx.h"
#include <iostream>
#include "DLL6.h"

void helloWorld(const std::string& pValue)
{
std::cout << pValue.c_str() << std::endl;
}

This is compiled using visual C++ v6.0 in a dll (Use of Multithreaded
runtime Dll - exceptions disabled - rtti enabled )

Then, I create the following executable with visual .net:

#include "stdafx.h"
#include "Dll6.h"

int main(int argc, char* argv[])
{
helloWorld(std::string("Hello world"));
return 0;
}
The program compiles and links properly but crashes in std::string

I've read in the msdn that the standard library has changed from VC6 to
VC7 .net. And I 've read compatibility issues stuff about STL and also
about the default runtime library.
So I ve tried to change the settings of the VC6 compiled dll in many
ways (enabling exceptions, /Nodefault ). I have also tried to change the
settings of the .net compiled main (forcing the use of old default
libraries msvcirt.lib ). Nothing worked.
I 'am stucked ..... :o(
If anybody has some tips.....
Thank you in advance,
Bye
Stephane
David Lowndes
7/7/2003 8:36:08 PM
[quoted text, click to view]

Stephane,

You've got 2 different implementations of the STL, and 2 different
run-time heaps, so it's no wonder it crashes.

Why not bite the bullet and make your life simpler and build it all
with the same version of the compiler?

Dave
--
stephane jaeger
7/8/2003 9:47:29 AM

Are you trying to tell me that the guys at Microsoft have choosen to
break compatibility with all previous dll written in the world as soon
as they have STL parameters in their interface ?
There should be a mean to link to a VC6 dll using VC .net, otherwise it
would sound too horrible for me since I don' have the source of the VC6
dll and building my app with .net is a compulsory (Not for technical
reasons, but for administrative and business reasons).
Anyway, thank you for answering.
If anybody has an Idea ....
Bye
Stephane

[quoted text, click to view]
stephane jaeger
7/8/2003 10:41:42 AM
I'd like to add some information about my "real life" problem since the
piece of code of the previous post was just a basic example.

I have a static library compiled using VC6. This static library has a C
Interface although the implementation is in C++ and takes advantage of
many VC6, C++ dlls, uses STL, and has exceptions disabled.

In addition to this static library I use the Qt library as a DLL
compiled using VC6.

I now want to build a simple app using VC .NET that creates a GUI using
the Qt dll and that makes calls to the static library. Obviously, as the
static library uses VC6 dlls, I also need to link my executable with the
corresponding .lib.
My app compiles and links fine with VC . Net, but crashes ( launches an
exception) into a static initialization of a string static member of my
static library. I do not understand why since there are no objects
exchanged between the app and the static lib since the lib has a simple
C interface (The fact of having both VC6 and VC .NET rt lib loaded in
memory shouldn't be a problem in this case ? ).
If Anybody has some Idea ?
Bye
Stephane
stephane jaeger
7/9/2003 9:44:53 AM
I've finally found a turn-around :
As I said before, I have a static library compiled using VC6. This
static library has a C Interface although the implementation is in C++
and takes advantage of many VC6, C++ dlls, uses STL, and has exceptions
disabled.
The trouble is that when linking an executable (VC .Net) with a static
library (VC6), the run-time library loaded by the VC6 static lib is the
VC . Net one. So when the static library exchanges complex data (such as
string object or stl, or template parameters) with the VC6 dll it
crashes even if memory allocation/unallocation policy is done side by
side. This happens because the VC6 dlls have the VC6 runtime library in
memory and because VC6 runtime lib and VC7 rt lib are not compatible on
many points (STL,....). One solution was to turn the static lib compiled
with VC6 in a VC6 dll . As the dll interface is in C, even if both
runtime library have to communicate, it is not a problem. (of course the
more practical solution would be to compile all components using the
same compiler - but for some out of topic reasons I could not do that).

[quoted text, click to view]
AddThis Social Bookmark Button