从vc6 dll创建wstring时,错误的指针或链接问题 [英] Bad pointer or link issue when creating wstring from vc6 dll

查看:309
本文介绍了从vc6 dll创建wstring时,错误的指针或链接问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在VC6上生成了一个DLL,并使用 wstring ,我试图在VC9项目中使用它。
在这个DLL中有一个更高级的类操作 wstring ,称为 UtfString



我在项目中正确导入了一切,但是当我调用:

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

它不会链接,即使函数原型是在lib ...



另一个发行者是当创建一个新的UtfString并且调试我的应用程序时,新的指针是< Bad Ptr>



我怀疑VC6 wstring 和VC9 wstring 但我不确定。我想避免修改原来的Dll。



如果有人可以为我更清楚的事情,并解释我是什么是真正的原因的问题将是巨大的



感谢您的回答,
Boris

解决方案

DONT EVEN TRY



字符串布局是不同的



p>

字符串类在VC6和VC9之间是完全不同的。



即使您可以连结,也很可能会发生崩溃。



是小字符串的16字节缓冲区和字符串st的指针size()> 15。
在VC9中,wstrings有一个联合,它是小字符串的8个wchar缓冲区和字符串s.t的指针。



您必须在VC6中分配大小()> 7。



如果跨边界传递字符串,请重新编译DLL。还有其他问题也太关于迭代器,太技术不能在这里描述。



对不起,重建


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

解决方案

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

这篇关于从vc6 dll创建wstring时,错误的指针或链接问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆