Perplex Posted January 12, 2017 Posted January 12, 2017 I've add Thread Local Storage in C++ project but Exception Handler error, What's the solution? Win32Project14.rar
atom0s Posted January 12, 2017 Posted January 12, 2017 (edited) Your issue is how you are linking to the CRT, change to: Multi-threaded Debug DLL (/MDd) Edited January 12, 2017 by atom0s 1
Perplex Posted January 12, 2017 Author Posted January 12, 2017 I want make portable executable so should compiled by (Multi-threaded (/MT))
kao Posted January 12, 2017 Posted January 12, 2017 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
atom0s Posted January 12, 2017 Posted January 12, 2017 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
havanacj13 Posted January 14, 2017 Posted January 14, 2017 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
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now