Microsoft KB Archive/267886

= Program May Cause Access Violation During Initialization =

Article ID: 267886

Article Last Modified on 2/19/2007

-

APPLIES TO


 * Microsoft Windows 2000 Server
 * Microsoft Windows 2000 Advanced Server
 * Microsoft Windows 2000 Professional Edition

-



This article was previously published under Q267886



SYMPTOMS
If a program file is implicitly linked to two DLLs (for example DLL1 and DLL2), and DLL2 is a MFC Winsock-based DLL that calls AfxSocketInit in its initialization routine and DLL1 is also implicitly linked to Advapi32.dll, the process may cause an access violation during its initialization.



CAUSE
This behavior occurs because of a problem in the Windows 2000 process loader.

When the program loads, the process loader loads all the DLLs, including DLL2 and DLL1, and tries to initialize each DLL one at a time. It first initializes DLL2. DLL2 is a MFC DLL; in its initialization it calls AfxSocketInit which dynamically loads the Ws2_32.dllWinsock DLL and tries to initialize it.

Ws2_32.dll is implicitly linked to Advapi32.dll and tries to load it, but it is already loaded (because DLL1 has Advapi32.dll as its dependency, which is loaded in memory). Because Advapi32.dll is loaded, Ws2_32.dll calls RegOpenKeyEx function in Advapi32.dll, which uses a critical section in Advapi32.dll. Because Advapi32.dll is loaded in memory but not yet initialized, accessing the uninitialized critical section causes the process to halt.



RESOLUTION
To resolve this problem, change the linking order in the project settings. Link DLL2.lib prior to DLL1.lib in the linker options.



STATUS
Microsoft has confirmed that this is a problem in the Microsoft products that are listed at the beginning of this article.



MORE INFORMATION
The problem also exists in Microsoft Windows NT 4.0, but it does not appear because User32.dll has a dependency on Advapi32.dll. This does not exist in Windows 2000.

Keywords: kbenv kbprb KB267886

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.