问题
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
回答1:
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
来源:https://stackoverflow.com/questions/1175330/bad-pointer-or-link-issue-when-creating-wstring-from-vc6-dll