简体   繁体   中英

DLL_THREAD_ATTACH not called when a COM DLL is invoked via IIS app pool w3wp.exe

I'm getting some DLL_THREAD_ATTACH notifications in my COM DLL, but none from the app pool worker threads, from which my COM DLL is actually invoked.

Subsequently, calls to the DLL initiated from IIS arrive on threads for which DLL_THREAD_ATTACH was never called.

Only the first thread of the app pool is notified when the DLL is attached to dllhost.exe (via DLL_PROCESS_ATTACH).

Is this a defect or a feature, and is there any workaround?

DLL_THREAD_ATTACH is often misunderstood. You don't give enough information, but it is likely that your problem is due to this :

From the MSDN documentation , emphasis mine :

DLL_THREAD_ATTACH | The current process is creating a new thread .

On the same page :

There are cases in which the entry-point function is called for a terminating thread even if the entry-point function was never called with DLL_THREAD_ATTACH for the thread:

  • The thread was the initial thread in the process, so the system called the entry-point function with the DLL_PROCESS_ATTACH value.
  • The thread was already running when a call to the LoadLibrary function was made, so the system never called the entry-point function for it .

To work around this, you can either manually enumerate every thread of a process when DLL_PROCESS_ATTACH . You can also do a first time init when your DLL functions are invoked on a new thread. Obviously, you can also create the threads AFTER the DLL is loaded, if it is possible.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM