PRB: Error Message Box Returned When DLL Load Fails

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, 4.0
    • Microsoft Windows 95


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:

Q94248 HOWTO: Use the C Run Time


REFERENCES

For more information on the DLL entrypoint, please search on the topic DllEntryPoint in the Win32 API help file.

Additional query words:

Keywords : kbDLL kbKernBase kbGrpKernBase
Version : winnt:3.5,3.51,4.0
Platform : winnt
Issue type : kbprb


Last Reviewed: October 19, 1999
© 2000 Microsoft Corporation. All rights reserved. Terms of Use.