使用声明为 __declspec(thread) 的变量会导致崩溃
我有一个使用静态线程本地存储 (__declspec(thread)
) 的 DLL(用 C 语言编写),并且我想从 Visual Basic 图形界面使用此 DLL。
不幸的是,当在 Windows XP 上运行该接口时,使用静态线程本地存储的 DLL 在尝试访问其线程变量时会崩溃。
我该如何解决这个问题?
谢谢, 问候
G.B.
聚苯乙烯 我不想修改DLL。
I have a DLL (written in C) that uses static thread local storage (__declspec(thread)
), and I want to use this DLL from a Visual Basic graphic interface.
Unfortunately, when running the interface on Windows XP that DLL which use static thread local storage crashes when it try to acess its thread variables.
How can I solve this problem?
Thanks,
Regards
G.B.
PS
I would like to not modify the DLL.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是静态 TLS 的已知限制。尽管您没有显式调用
LoadLibrary()
,但 VB 运行时会代表您执行此操作。请注意,此限制已从 Vista 中取消。据我所知,最全面的参考资料来自 Ken Johnson 的博客。
如果您可以将 DLL 包含在生成的 .exe 的导入表中,您也许能够解决这个问题,这可能会涉及一些 PE 黑客攻击,而且我还不确定这是否是一个可行的策略。否则您需要更改 DLL。
This is a known limitation of static TLS. Although you aren't explicitly calling
LoadLibrary()
, the VB runtime does so on your behalf.Note that this limitation has been lifted from Vista. The most comprehensive reference that I know of is on Ken Johnson's blog.
You may be able to get around the problem if you could get the DLL included in the imports table of the generated .exe, which would likely involve some PE hacking and I'm far from certain it's a viable strategy. Otherwise you'll need to change the DLL.