INPROC: Demonstrates an In-Process Automation Server Application

Click to open or copy the INPROC project files.

INPROC is an in-process Automation (formerly OLE Automation) server. Unlike the other automation server samples provided, INPROC can be loaded as a dynamic-link library (DLL) in the client's address space. In-process servers are usually more efficient than servers implemented as separate EXEs because a remote procedure call (RPC) is not necessary to invoke methods on the objects implemented by the server. The DLL version of INPROC cannot be run directly; DLLs cannot be run as EXEs can. To test INPROC, you must "drive" it from a client application. INPROC can be driven from Visual Basic® or from Visual C++®. See the IPDRIVE sample for an example of driving INPROC from Visual C++.

You can build an EXE version of INPROC (EXE variants are one of the targets you can choose in the sample's project file). These EXE versions do nothing more than register themselves in the Windows registry.

To register the DLL version of INPROC, use the .REG file provided (run regedit INPROC.REG) or use REGSVR from the CONTROLS sample. If you use REGEDIT, be sure that Inproc.dll is on the system path (you could also modify the .reg file to refer to the path of Inproc.dll explicitly).

The CVariantMap class implements a VARIANT to VARIANT map. This allows any VARIANT to be mapped to any other VARIANT. Although this is probably not useful to Visual C++ programmers (who would probably use CMap directly), it does bring the power of MFC's collection classes to Visual Basic users. The CVariantMap class is accessed by the name mfc.inproc.varmap. This is how the object is registered in the Windows registry. CVariantMap implements the "standard" collection methods and properties as well as the _NewEnum method.

The CStringCollect class implements an array of strings. Its implementation is simpler than the CVariantMap class, even though it implements many of the same automation features as CVariantMap. The CStringCollect object is accessed by the name mfc.inproc.strcoll. It implements most of the "standard" collection methods and properties and is a good example for how to implement your own collections. Of particular interest is its implementation of the _NewEnum method, which allows Visual Basic users to use the "For Each... In" syntax when enumerating the contents of a collection. CStringCollect uses CEnumVariant to implement this functionality (it implements IEnumVARIANT using MFC's interface maps). You may find CEnumVariant useful in your own applications.

Finally, the sample implements a few "dummy properties," which are used simply to compare the performance of in-process servers and LocalServer servers. These are the properties tested by IPDRIVE's Test1 and Test2 buttons.

This sample demonstrates the following keywords:

AfxIsValidAddress; AfxMessageBox; AfxOleInit; AfxOleLockApp; AfxOleUnlockApp; AfxThrowMemoryException; AfxThrowOleException; CCmdTarget::EnableAutomation; CCmdTarget::GetIDispatch; CCmdTarget::OnFinalRelease; CString::AllocSysString; CWinApp::Enable3dControls; CWinApp::InitInstance; CWinApp::RunAutomated; CWinApp::RunEmbedded; DllCanUnloadNow; DllGetClassObject; min