Perplex

Thread Local Storage Exception Handler error

6 posts in this topic

I've add Thread Local Storage in C++ project but Exception Handler error,  What's the solution?

Win32Project14.rar

Share this post


Link to post
Share on other sites

Your issue is how you are linking to the CRT, change to:

Multi-threaded Debug DLL (/MDd)

Edited by atom0s
1 person likes this

Share this post


Link to post
Share on other sites

I want make portable executable so should compiled by (Multi-threaded (/MT))

Share this post


Link to post
Share on other sites

The actual problem (most likely) is that you're using functions from MS CRT library - which gets initialized by code at EXE entrypoint. During TLS callback it's not initialized yet.

1 person likes this

Share this post


Link to post
Share on other sites
10 hours ago, Perplex said:

I want make portable executable so should compiled by (Multi-threaded (/MT))

Like I said, the way you are linking is preventing it from working properly. The CRT is loaded after TLS callbacks occur when you statically link to it. Meaning the calls and data you are trying to use are not ready yet. When you link dynamically to it, things are loaded as they are requested so you can use them anywhere. If you want to keep things portable, you need to avoid using CRT specific calls (for example in your case wprintf) within the TLS callback. You shouldn't be doing things like that in a TLS callback anyway, it is used to initialize data.

1 person likes this

Share this post


Link to post
Share on other sites

That's right. TLS callbacks are called very early in the loading process. Maybe not all things are initialized at this point. This depends on loading order e.g. of DLL's, etc. You should not do there any "big" things inside a TLS Callback.

It's nearly the same kind of problems as you should not do extensive things in DllMain().

https://msdn.microsoft.com/en-us/library/windows/desktop/ms682583(v=vs.85).aspx

1 person likes this

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now