views:

295

answers:

1

I got a DLL generated on VC6 and using wstring, and I'm trying to use it in a VC9 project. In this DLL there is a higher level class manipulating wstring, called UtfString.

I got everything imported correctly in my project, but when I call:

std::wstring test;
UtfString uTest(test);

it won't link, even if the function prototype is in the lib...

The other issuer is that when create a new UtfString, and debug my app, the new pointer is <Bad Ptr>.

I suspect a conflict between VC6 wstring and VC9 wstring but I'm not sure. I want to avoid to modify the original Dll.

It would be great if someone could make things more clear for me, and explain me what is the real reason of the problem.

Thanks in advance for your answer, Boris

+2  A: 

DONT EVEN TRY

the string layouts are different

you can't do that.

The string class is entirely different between VC6 and VC9.

Even if you were able to link you will most likely crash.

In VC9 strings have a union that is 16 byte buffer for small strings and a pointer for string s.t. size()>15. In VC9 wstrings have a union that is 8 wchar buffer for small strings and a pointer for string s.t. size()>7.

in VC6 all string buffer space is allocated on the heap.

YOU must recompile the DLL if you pass strings across the boundary. There are other issues too regarding iterators that are too technical to describe here.

sorry gotta rebuild

And the name mangling reflects that the VC6 and VC9 strings are truly distinct types.
MSalters
Thanks for your answer, I actually figured that out last night. Unfortunately I cannot recompile my dll with VC9. So my solutions are to either make a string wrapper in VC6, or to change the function prototypes and replace the wstring by some char* or wchar_t
Boris Gougeon
Do you know if I'll experience the same issue with wchar_t? should I user char* only?
Boris Gougeon