Crash using variables declared __declspec(thread)

2019-07-05 23:32发布

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.

1条回答
混吃等死
2楼-- · 2019-07-06 00:28

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.

查看更多
登录 后发表回答