Microsoft KB Archive/130842

= SAMPLE: MFCINP32 Inproc 32-bit MFC Automation Object =

Article ID: 130842

Article Last Modified on 8/5/2004

-

APPLIES TO


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

-



This article was previously published under Q130842



SUMMARY
MFC's App Wizard in Visual C++ version 2.0 will not generate an inproc OLE Automation server. This article gives steps you can follow to create an inproc automation server using MFC. You can also obtain a sample (MFCINP32) from the Microsoft Download Center that is a 32-bit inproc automation object created by following the steps in this article.



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

MFCinp32.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.

NOTE: The App Wizard in Visual C++ version 2.1 and above does generate an inproc OLE Automation server.

MFC's 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 provides the instructions to do this.

Steps to Create 32-Bit Inproc Automation Object in MFC
It is assumed that Visual C++ version 2.0 and the Control Development Kit have been installed.  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 of type Dynamic-Link Library. (Do not select MFC AppWizard DLL.) Add INPROC.CPP to this project.  Create an .ODL file (INPROC.ODL) containing a modification of the following code, and add it to the project. [ uuid(ABEBE5A0-0C69-11CE-B774-00DD01103DE1), version(1.0) ] library inproc {          importlib("stdole32.tlb"); //     }; Don't use the same UUID as the one shown here. Instead generate a new one by running GUIDGEN.EXE, and use that value. The library name can be changed from inproc to a name more appropriate for your project. The version number can also be changed.   Create the .DEF file (INPROC.DEF) containing the following code, and add it to the project. LIBRARY  INPROC EXPORTS DllGetClassObject DllCanUnloadNow DllRegisterServer The library name can be changed from INPROC to a name more appropriate for your project.  Select Project Settings, as follows:

 In the ProjectSettings dialog box under General, select Use MFC in a shared DLL. In the ProjectSettings dialog box under C/C++, remove _AFXDLL, and add _USRDLL and _WINDLL under Preprocessor definitions.</li> In the ProjectSettings dialog under Link, add the following libraries to Object/Library modules:

ole32.lib oleaut32.lib

</li></ol> </li> 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 .RC file and running ClassWizard again.</li> Open your .RC file or create a new .RC file by choosing New from the File menu and selecting Resource Script. Save the new .RC file (INPROC.RC). Now bring up ClassWizard. The .CLW file will now be built after you choose OK in the SelectSourceFiles dialog box. Follow these steps:

<ol style="list-style-type: lower-alpha;"> Select the OLE Automation tab in the ClassWizard dialog.</li> 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 is used by the automation controller/client to create the object. (The sample creates a class called TestObject that 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> Build the project. Register the inproc Automation object by using the Tools/RegisterControl menu.</li> NOTE: A 16 bit controller like Visual Basic version 3.0 cannot control a 32-bit inproc automation object because 16-bit to 32-bit interoperability is not supported with inproc automation objects. Instead, write a 32-bit controller to control this 32-bit inproc automation object.</li></ol>

Additional query words: MFCinp32 kbole kbfile

Keywords: kbdownload kbautomation KB130842

-

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

© Microsoft Corporation. All rights reserved.