Why did every Windows 3.0 DLL have an exported function called WEP?

Raymond Chen

Raymond

One of the quirks of Windows 3.0 was this function called WEP, which was exported by every DLL. And yet if you looked at every DLL, youā€™d see that the function did nothing but return.

Whatā€™s the deal with this function that everybody has, but which does nothing?

WEP stands for Windows Exit Procedure. Starting in Windows 3.0, Windows would call a DLLā€™s WEP function with a single boolean parameter. It called the WEP function with FALSE immediately before unloading the DLL from memory, and it called the WEP function with TRUE immediately before shutting down. Of course, the DLLā€™s WEP function was called only once per instance, because once youā€™re unloaded, youā€™re not going to be around to receive the shutdown notification.

Since the WEP function was called as part of the unload or shutdown process, you were extremely limited in what you could do. The function itself had to be in a non-moveable segment, and the import entry needed to be in the resident name table. You canā€™t call any function that might result in a call to LoadĀ­Module. You canā€™t call into another DLL at shutdown, because the other DLL might have already run its shutdown code.

In practice, everybody just returned without doing anything.

Raymond Chen
Raymond Chen

Follow Raymond