从 vc6 dll 创建 wstring 时出现错误的指针或链接问题

发布于 2024-07-29 09:01:22 字数 522 浏览 1 评论 0原文

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

我在项目中正确导入了所有内容,但是当我调用时:

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

即使函数原型位于库中,它也不会链接...

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

我怀疑 VC6 wstring 和 VC9 wstring 之间存在冲突,但我不确定。 我想避免修改原来的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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

少钕鈤記 2024-08-05 09:01:23

甚至不要尝试

字符串布局不同,

你不能这样做。

VC6 和 VC9 的字符串类完全不同。

即使您能够链接,您也很可能会崩溃。

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

在VC6中,所有字符串缓冲区空间都在堆上分配。

如果跨越边界传递字符串,则必须重新编译 DLL。 关于迭代器还有其他问题,技术性太强,无法在此描述。

抱歉,必须重建

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文