0

I have a situation where my Windows autostart Service application is explicitly loading and calling a startup routine in a "parent" DLL1.DLL (using LoadLibrary/GetProcAddress - no import libraries). The startup routine in the "parent" DLL is in turn explicitly loading several "child" DLLs: DLL2, DLL3 and DLL4. There are no LoadLibrary calls in any DLLMain routines. The Service executable and all the DLLs are developed in C.

On Windows 7 this all works fine, but on Windows 10 the service is randomly hanging in Start Pending after reboot. Debug output shows that it is not returning from the LoadLibrary where the parent DLL1 is loading one of the child DLLs. Debug output is also showing that the DLLMain routine of the child DLL is not even being called.

All of the DLLMain routines are very simple. All they do is InitializeCriticalSection if ul_reason_for_call == 0. They do nothing funcky like calling LoadLibrary inside DLLMain.

I have read several articles/threads about the Windows 10 Thread Pool such as this and this.

From my understanding, Windows 10 multithreads the loading of implicit LoadLibrary (ie, via Import Library). But does it also multithread the loading of explicit LoadLibrary? For example, might child DLL2 still be loading while child DLL3 is starting to load?

Since this is a random thing it must clearly be a timing and/or thread issue. Any suggestions would be greatly appreciated. I've spent a couple of weeks on this and I'm stumped.

Neil Weicher
  • 2,370
  • 6
  • 34
  • 56
  • Could you have autostart Service application load all the libraries sequentially? Any multi-threading problem might be circumvented that way. At least just to test, then later you can find out what happens in more detail. – Paul Ogilvie Oct 06 '18 at 14:25
  • 2
    . o O (i could swear i just left a link here which is now gone!? Anyway: ) https://blogs.msdn.microsoft.com/junfeng/2006/11/20/debugging-loadlibrary-failures/ – Swordfish Oct 06 '18 at 14:40
  • @PaulOgilvie - I'm not sure I understand what you mean by loading the libraries sequentially. They are loaded by one LoadLibary after another. I wouldn't know how to load them non-sequentially unless they were loaded in separate threads kicked off by the parent DLL, which is not the case. – Neil Weicher Oct 06 '18 at 15:24
  • I seem to have fixed it by adding a Sleep(10) before each LoadLibrary. I don't understand it, but I guess the yield gives the Windows loader time to do its thing. – Neil Weicher Oct 10 '18 at 13:30

0 Answers0