Struct size containing vector<T> different sizes between DLL and EXE

久未见 提交于 2019-12-10 18:32:31

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/2862600/struct-size-containing-vectort-different-sizes-between-dll-and-exe

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