Putting a UI in a DLL

Have you ever wanted to put an MFC user interface in a DLL call? In other words, how do you create a DLL function that any program can call and bring up an MFC user interface?

This is easy to do if you take advantage of CWinThread, the MFC object that represents a thread. You should know that CWinThread is the base class for CWinApp and most of the things you think belong to CWinApp really belong to CWinThread.

You can use AfxBeginThread in your exported DLL function to create an instance of a class you derived from CWinThread (use Class Wizard to derive the new class). Then, in the InitInstance function, you do all the normal things you do in an InitInstance including creating a main window.

You'll find an example of this in Chapter 11 of my upcoming MFC Black Book for Coriolis. Look for details about this book in the Book Nook soon.