Microsoft KB Archive/130843

= SAMPLE: MFCINP16: Inproc 16-bit MFC Automation Object =

Article ID: 130843

Article Last Modified on 3/3/2005

-

APPLIES TO


 * Microsoft OLE 1.0
 * Microsoft Foundation Class Library 4.2, when used with:
 * Microsoft Visual C++ 1.52 Professional Edition

-



This article was previously published under Q130843



SUMMARY
MFC's App Wizard will not generate an inproc OLE Automation server. This article gives you the steps to follow to create an inproc automation server using MFC. MFCINP16, a sample available from the Microsoft Download Center, is a 16-bit inproc automation object that was created using the steps in this article.



MORE INFORMATION
The following file is available for download from the Microsoft Download Center:

MFCinp16.exe

For additional information about how to download Microsoft Support files, click the following article number to view the article in the Microsoft Knowledge Base:

119591 How to Obtain Microsoft Support Files from Online Services

Microsoft scanned this file for viruses. Microsoft used the most current virus-detection software that was available on the date that the file was posted. The file is stored on security-enhanced servers that help to prevent any unauthorized changes to the file.

The MFC App Wizard doesn't generate inproc (DLL) OLE servers because it is not possible for MFC to fully implement one that can open into a separate window. MFC needs to hook into the client's main message retrieval loop to translate accelerators of the separate window and to implement idle-time processing. OLE doesn't provide such a mechanism. It is entirely possible to implement an inproc server in MFC with no user interface or with a very simple user interface. This article shows you how.

Steps to Create a 16-Bit Inproc Automation Object in MFC
It is assumed that you installed Visual C++ version 1.51 or greater and the Control Development Kit.

 Use INPROC.CPP, INPROC.H, and STDAFX.H from the sample as the starting point. Copy these into a new directory. The names INPROC.CPP and INPROC.H can be changed to something more appropriate for your project. Create a new project by choosing New from the Project menu and selecting the Windows dynamic-link library as the type. Add INPROC.CPP to this project. (The sample uses inproc for the project name.)  From the Options menu, choose Project and select Compiler. Add the following in the C/C++ CompilerOptions dialog box under the CustomOptions category in the OtherOptions edit control: /D "_USRDLL" From the Options menu, choose Project and select Linker. Add the following libraries in the LinkerOptions dialog box under the Input category in the Libraries edit control: ole2, compobj, ole2disp, typelib, ole2nls, mfcoleui, storage  Choose ClassWizard from the Project menu. ClassWizard will complain that the .CLW file does not exist. It will ask you to rebuild the .CLW file by opening the project in App Studio and running ClassWizard. Open AppStudio by choosing it from the Tools menu. Save the resource file, and run ClassWizard from AppStudio by choosing ClassWizard from the Resource menu. The CLW file will now be built after you choose OK in the SelectSourceFiles dialog box. Complete the following steps:

 Select the OLE Automation tab in the MFC ClassWizard dialog. Choose the AddClass button, and add a class of type CCmdTarget.</li> Select the OLEAutomation check box.</li> Select the OLECreatable check box, and provide an ExternalName (progID) if this is a top-level automation object. This external name will be used by the automation controller/client to create the object. (The sample creates a class called TestObject, which has an external name Inproc.TestObject.)</li></ol> </li> Add the required automation properties and methods to the newly created class. (The sample creates a method called TestMethod that returns void and has no parameters. The method calls MessageBeep.)</li> Attempt to build the project. Visual C++ will ask if you want to create a default .DEF file. Edit the default .DEF file to export the following:

DllGetClassObject

DllCanUnloadNow

DllRegisterServer

</li> Build the project. Register the inproc Automation object by choosing RegisterControl from the Tools menu.</li> VB.MAK and VB.FRM in the sample are Visual Basic version 3.0 files that you can use to control the object.</li></ol>

Additional query words: MFCINP16 kbole kbfile

Keywords: kbdownload kbautomation KB130843

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.