Jump to content
Tuts 4 You

Thread Local Storage Exception Handler error


Perplex

Recommended Posts

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.

  • Like 1
Link to comment
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.

  • Like 1
Link to comment

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

  • Like 1
Link to comment

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
×
×
  • Create New...