Posted January 12, 20178 yr I've add Thread Local Storage in C++ project but Exception Handler error, What's the solution? Win32Project14.rar
January 12, 20178 yr Your issue is how you are linking to the CRT, change to: Multi-threaded Debug DLL (/MDd) Edited January 12, 20178 yr by atom0s
January 12, 20178 yr Author I want make portable executable so should compiled by (Multi-threaded (/MT))
January 12, 20178 yr 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.
January 12, 20178 yr 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.
January 14, 20178 yr 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
Create an account or sign in to comment