
When a child window is created in an ObjectWindows DLL and the parent
window is created by a non-ObjectWindows application, the parent-child
relationship must be simulated in the ObjectWindows DLL. This is done by
constructing an alias window object in the ObjectWindows DLL that is
associated with the parent window whose handle is speciļ¬ed on a DLL call.
In the following code, the exported function CreateDLLWindow is in an
ObjectWindows DLL. The function will work for both ObjectWindows and
non-ObjectWindows applications.
BOOL far _export
CreateDLLWindow(HWND parentHWnd)
{
TWindow* parentAlias = GetWindowPtr(parentHWnd); // check if an OWL window
if (!parentAlias)
parentAlias = new TWindow(parentHWnd); // if not, make an alias
TWindow* window = new TWindow(parentAlias, "Hello from a DLL!");
window->Attr.Style |= WS_POPUPWINDOW | WS_CAPTION | WS_THICKFRAME
| WS_MINIMIZEBOX | WS_MAXIMIZEBOX;
window->Attr.X = 100; window->Attr.Y = 100;
window->Attr.W = 300; window->Attr.H = 300;
return window->Create();
}
CreateDLLWindow determines if it has been passed a non-ObjectWindows
window handle by the call to GetWindowPtr, which returns 0 when passed
a non-ObjectWindows window handle. If it is a non-ObjectWindows
window handle, an alias parent TWindow object is constructed to serve as
the parent window.
Implicit and explicit loading
Implicit loading is done when you use a .DEF or import library to link your
application. The DLL is loaded by Windows when the application using the
DLL is loaded.
Explicit loading is used to load DLLs at run time, and requires the use of
the Windows API functions LoadLibrary to load the DLL and GetP ocAddressr
to return DLL function addresses.
Mixing static and dynamic-linked libraries
The ObjectWindows libraries are built using the BIDS (container class)
libraries, which in turn are built using the C run-time library.
Chapter 16, ObjectWindows dynamic-link libraries
351