SAMPLE: MFCINP32 Inproc 32-bit MFC Automation Object

ID: Q130842


The information in this article applies to:
  • Microsoft OLE, version 2.03
  • Microsoft Foundation Classes (MFC), used with:
    • Microsoft Visual C++, 32-bit Editions, version 2.0


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. Click the file name below to download the file:

MFCinp32.exe
For more information about how to download files from the Microsoft Download Center, please visit the Download Center at the following Web address
http://www.microsoft.com/downloads/search.asp
and then click How to use the Microsoft Download Center.

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


  2. Create a new project of type Dynamic-Link Library. (Do not select MFC AppWizard DLL.) Add INPROC.CPP to this project.


  3. 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");
              //{{AFX_APPEND_ODL}}
          }; 
    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.


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


  5. Select Project Settings, as follows:

    1. In the ProjectSettings dialog box under General, select Use MFC in a shared DLL.


    2. In the ProjectSettings dialog box under C/C++, remove _AFXDLL, and add _USRDLL and _WINDLL under Preprocessor definitions.


    3. In the ProjectSettings dialog under Link, add the following libraries to Object/Library modules:
      ole32.lib oleaut32.lib




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


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

    1. Select the OLE Automation tab in the ClassWizard dialog.


    2. Choose the AddClass button, and add a class of type CCmdTarget.


    3. Select the OLEAutomation check box.


    4. 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.)




  8. 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.)


  9. Build the project. Register the inproc Automation object by using the Tools/RegisterControl menu.


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


Additional query words: kbole kbfile

Keywords : kbole kbAutomation kbMFC kbOLE200 kbVC200 kbGrpCom kbDSupport
Version : :2.03
Platform : NT WINDOWS
Issue type :


Last Reviewed: December 7, 1999
© 2000 Microsoft Corporation. All rights reserved. Terms of Use.