包含向量的结构大小DLL 和 EXE 大小不同

发布于 2024-09-01 22:08:05 字数 347 浏览 2 评论 0原文

我遇到过这样的情况:EXE 程序导入 DLL 以进行单个函数调用。它的工作原理是传入自定义结构并返回不同的自定义结构。到目前为止,它工作得很好,直到我希望其中一个结构数据成员是一个向量 <我的结构>

当我在程序中执行 sizeof(vector) 时,我得到的大小为 20,但是当我从 DLL 内部执行此操作时,我得到的大小为 24。这种大小不一致会导致 ESP 指针错误。

谁能告诉我为什么 Vector <我的结构> DLL 中的大小与程序中的大小会不同吗?

我已经验证 DLL 和程序中的结构是相同的。

我将不胜感激有关该主题的任何帮助。谢谢。

I have this situation where an EXE program imports a DLL for a single function call. It works by passing in a custom structure and returning a different custom structure. Up till now it's worked fine until I wanted one of the structs data members to be a vector < MyStruct >

When I do a sizeof(vector< MyStruct >) in my program I get a size of 20 but when I do it from inside the DLL I get a size of 24. This size inconsistency is causing a ESP pointer error.

Can anyone tell me why a Vector < MyStruct > would be a different size in the DLL than in the program?

I have reverified that my structs in both the DLL and the Program are identical.

I would appreciate any help on the subject. Thank you.

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

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

发布评论

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

评论(1

梦中的蝴蝶 2024-09-08 22:08:05

当类有一个向量<...>时,我遇到类似的问题成员,并具有内联构造函数(在头文件中实现)。
无论DLL是Release还是DLL版本,就像EXE是Release版本一样,EXE中计算出的类的大小比DLL中少了3个字节,因此堆栈将被破坏。

此问题可以通过以下更改之一来解决:

  • 仅出现在 VC98(SP6) 中。换成VS2008,问题消失。

  • 将内联构造函数移至 CPP 文件,问题消失

希望有人能帮忙给出更详细的解释。

I meet similar issue when the class has a vector<..> member, and with an inline construct function(implemented in header file).
No matter DLL is release or dll version, as if as EXE is release version, size of that class calculated in EXE is 3 byte less than in DLL, thus the stack will be destroyed.

This problem can be fixed by one of below change:

  • It's only occured with VC98(SP6). Change to VS2008, issue disappears.

  • Move the inline construct function to CPP file, issue disappears
    too.

I hope someone can help to give a more detailed explanation.

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