[comp.windows.ms] Dynamically Linked Libraries

ib@apolling (Ivan N. Bach) (02/09/89)

>I'm having difficulty figuring out how to create and manage windows
>from a dynamic link library that is loaded from a main program after
>program initialization (the main program does not know the name or
>contents of the DLL until the DLL is selected from a list of DLLs
>on disk).  As I understand it from Petzold's book, DLLs do not receive
>messages from Windows and so must peek at the main program's message
>queue.  The only exception is for modal dialog boxes, which get their
>messages directly.  However, I really need full popup windows, or at
>least a modeless dialog box.
>
>Can anyone offer some suggestions (or maybe even a little code) about
>windows management from within a DLL?

I am familiar with Windows printer drivers which are built as DLLs.
The basic problem is that some application has opened a Window and you
don't have a handle to that window.  The answer to this problem is that
you don't need a handle to issue a call to the Windows "MessageBox"
function.  If you look at the sample source codee for the "cardfile"
application that comes with SDK, you will see that the program "ininput.c"
uses a NULL handle to display a message about insufficient memory when
Windows is not able to create a window.  If you want to display a short
message on top of any active window with "OK" and "Cancel" buttons, 
issue a call such as:

    if (MessageBox(NULL, (LPSTR)msgstr, (LPSTR)captionstr, 
         MB_OKCANCEL | MB_ICONEXCLAMATION | 
         MB_SYSTEMMODAL) == IDCANCEL) {
         fUserAbort = TRUE;
         break;
    }

where "msgstr" contains your message and "captionstr" contains the
caption for message box.

Ivan Bach, QMS, Inc.