Bad pointer or link issue when creating wstring from vc6 dll

Deadly 提交于 2019-12-14 03:08:39

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!