INPROC Sample: Demonstrates an In-Process Automation Server Application

The INPROC sample is an in-process Automation (formerly OLE Automation) server. Unlike the other MFC automation server samples, 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.

Note

Some of the samples, such as this one, have not been modified to reflect the changes in the Visual C++ wizards, libraries, and compiler, but still demonstrate how to complete your desired task.

Security noteSecurity Note

This sample code is intended to illustrate a concept, and it shows only the code that is relevant to that concept. It may not meet the security requirements for a specific environment, and it should not be used exactly as shown. We recommend that you add security and error-handling code to make your projects more secure and robust. Microsoft provides this sample code "AS IS" with no warranties.

To get samples and instructions for installing them:

To access samples from Visual Studio

  • On the Help menu, click Samples.

    By default, these samples are installed in drive:\Program Files\Microsoft Visual Studio 10.0\Samples\.

  • For the most recent version of this sample and a list of other samples, see Visual Studio Samples on the MSDN Web site.

Building and Running the Sample

To build and run the INPROC sample

  1. Open the solution inproc.sln.

  2. On the Build menu, click Build.

  3. Register INPROC's DLL using the project's .reg file, that is, either run regedit INPROC.REG, or use REGSVR from the REGSVR sample.

    If you use REGEDIT, be sure that Inproc.dll is on the system path. Alternately, you can modify the .reg file to refer to the path of Inproc.dll explicitly.

    A DLL cannot be run stand alone, as an EXE can; therefore, 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++.

    Note

    You can build an EXE version or a DLL version of INPROC. Set the EXE variant in the sample's project settings. An EXE version of INPROC only registers itself in the Windows registry.

INPROC Classes

The CVariantMapclass 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 the MFC 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.

Keywords

This sample demonstrates the following keywords:

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

See Also

Other Resources

MFC Samples