PRB: Error Message Box Returned When DLL Load Fails

Last reviewed: December 17, 1996
Article ID: Q117330
The information in this article applies to:
  • Microsoft Win32 Application Programming Interface (API) included with:

        - Microsoft Windows NT versions 3.5, 3.51, and 4.00
        - Microsoft Windows 95 version 4.0
    

SYMPTOMS

Under Windows NT, when you load a DLL, a message box titled "Invalid DLL Entrypoint" is displayed and has the following text:

   The dynamic link library <name> is not written correctly.
   The stack pointer has been left in an inconsistent state.
   The entry point should be declared as WINAPI or STDCALL.
   Select YES to fail the DLL load. Select NO to continue
   execution. Selecting NO may cause the application to operate
   incorrectly.

Under Windows 95, the message box is titled "Error starting program" and the text is:

   The <dll file name> file cannot start. Check the file to
   determine the problem.

The user is not given a choice to continue, only an OK button. Pressing the OK button fails program load.

CAUSE

The system expects DLL entrypoints to use the _stdcall convention. If you use the _cdecl convention, the stack is not properly restored and subsequent calls into the DLL can cause a general protection fault (GPF).

This error message is new to Windows NT, version 3.5. Under Windows NT, version 3.1, the DLL is loaded without an error message, but the application usually causes a GPF when calling a DLL routine.

RESOLUTION

Correct the prototype of your entrypoint. For example, if your entrypoint is as follows:

   BOOL DllMain( HANDLE hDLL, DWORD dwReason, LPVOID lpReserved)

change it to the following:

   BOOL WINAPI DllMain( HANDLE hDLL, DWORD dwReason, LPVOID lpReserved)

Then, link with the following linker option to specify the entry point if you are using the C run-time:

   -entry:_DllMainCRTStartup$(DLLENTRY)

MORE INFORMATION

If you are using the Microsoft C run-time, you need to use the entry point given in the RESOLUTION section in order to properly initialize the C run- time. For additional information, please see the following article in the Microsoft Knowledge Base:

   ARTICLE-ID: Q94248
   TITLE     : Using the C Run Time

REFERENCES

For more information on the DLL entrypoint, please search on the topic "DllEntryPoint" (without the quotes) in the Win32 API help file.


KBCategory: kbprg kbprb
KBSubcategory: BseDll
Additional reference words: 3.50 3.51 4.00 libmain


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: December 17, 1996
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.