Category : C Source Code
Archive   : C-ALL.ZIP
Filename : TI644.ASC

Output of file : TI644.ASC contained in archive : C-ALL.ZIP

PRODUCT : Borland C++ NUMBER : 644
DATE : September 17, 1991 PAGE : 1/1

TITLE : Windows DLL and Fatal Exit Code=0x001A

Fatal Exit Code=0x001A is not documented by the SDK but what it
seems to mean is that an attempt has been made to FreeLibrary() a
DLL which has registered a GLOBALCLASS window class still in use
by another open window.

For example, a window class with the style CS_GLOBALCLASS is
registered in order to make a custom control (like "button",
"checkbox", etc.). In the main program, a LoadLibrary() and a
CreateWindow() are executed to create a child window of that
custom class.

In a WM_DESTROY message handler, a FreeLibrary() is done followed
by a PostQuitMessage(0). Seems like a reasonable procedure but
results in a Fatal Exit Code=0x001A from Windows when the DLL is
used. Puzzled?

A careful reading of the SDK reference indicates that WM_DESTROY
is sent to a parent window BEFORE its children are destroyed.

The library freed from memory by the FreeLibrary() call contained
the necessary class information for the child window. Since this
is all happening inside of a WM_DESTROY handler, this child
window isn't closed yet and the result is the Fatal Exit

One solution is to trap WM_CLOSE and close the affected windows
prior to the FreeLibrary() call:

case WM_CLOSE:
DestroyWindow(handle of main window);
DestroyWindow(handle of first child window);
DestroyWindow(handle of second child window);
FreeLibrary(library handle);

This effectively forces Windows to close all of the children
BEFORE freeing the library that they are based on.

  3 Responses to “Category : C Source Code
Archive   : C-ALL.ZIP
Filename : TI644.ASC

  1. Very nice! Thank you for this wonderful archive. I wonder why I found it only now. Long live the BBS file archives!

  2. This is so awesome! 😀 I’d be cool if you could download an entire archive of this at once, though.

  3. But one thing that puzzles me is the “mtswslnkmcjklsdlsbdmMICROSOFT” string. There is an article about it here. It is definitely worth a read: