简体   繁体   English

通过IIS应用程序池w3wp.exe调用COM DLL时未调用DLL_THREAD_ATTACH

[英]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. 我在COM DLL中收到一些 DLL_THREAD_ATTACH通知,但没有从应用程序池工作程序线程中获得任何通知,而实际上是从这些线程调用我的COM DLL。

Subsequently, calls to the DLL initiated from IIS arrive on threads for which DLL_THREAD_ATTACH was never called. 随后,从IIS启动的对DLL的调用到达从未调用过DLL_THREAD_ATTACH的线程。

Only the first thread of the app pool is notified when the DLL is attached to dllhost.exe (via DLL_PROCESS_ATTACH). 当DLL附加到dllhost.exe(通过DLL_PROCESS_ATTACH)时,仅通知应用程序池的第一个线程。

Is this a defect or a feature, and is there any workaround? 这是缺陷还是功能,是否有任何解决方法?

DLL_THREAD_ATTACH is often misunderstood. DLL_THREAD_ATTACH常常被误解。 You don't give enough information, but it is likely that your problem is due to this : 您没有提供足够的信息,但是您的问题很可能是由于以下原因:

From the MSDN documentation , emphasis mine : MSDN文档中 ,重点是:

DLL_THREAD_ATTACH | 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: 在某些情况下,即使从未使用线程的DLL_THREAD_ATTACH调用入口点函数,也要为终止线程调用入口点函数:

  • The thread was the initial thread in the process, so the system called the entry-point function with the DLL_PROCESS_ATTACH value. 线程是进程中的初始线程,因此系统使用DLL_PROCESS_ATTACH值调用了入口点函数。
  • 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 . 调用LoadLibrary函数时该线程已经在运行,因此系统从未为其调用入口点函数

To work around this, you can either manually enumerate every thread of a process when DLL_PROCESS_ATTACH . 要解决此问题,您可以在DLL_PROCESS_ATTACH时手动枚举进程的每个线程。 You can also do a first time init when your DLL functions are invoked on a new thread. 您也可以在新线程上调用DLL函数时进行首次初始化。 Obviously, you can also create the threads AFTER the DLL is loaded, if it is possible. 显然,如果可能的话,还可以在加载DLL之后创建线程。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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