SAMPLE: MFCINP32 Inproc 32-bit MFC Automation Object

Last reviewed: October 10, 1997
Article ID: Q130842
2.03 2.00 WINDOWS NT kbole kbprg kbfile kbcode kbwebcontent

The information in this article applies to:

  • Microsoft OLE version 2.03
  • Microsoft Foundation Classes (MFC) included with: Microsoft Visual C++, 32-bit Edition, 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 Software Library that is a 32-bit inproc automation object created by following the steps in this article.

You can find MFCINP32.EXE (size: 25194 bytes) 
                         , a self-extracting file, on these services:

  • Microsoft's World Wide Web site on the Internet

          On the www.microsoft.com home page, click the Support icon
          Click Knowledge Base, and select the product
    
          Enter kbfile MFCINP32.EXE (size: 25194 bytes) 
                                   , and click GO!
          Open the article, and click the button to download the file
    
    
  • Internet (anonymous FTP)

          ftp ftp.microsoft.com
          Change to the Softlib/Mslfiles folder
          Get MFCINP32.EXE (size: 25194 bytes) 
    
  • The Microsoft Network

          On the Edit menu, click Go To, and then click Other Location
          Type "mssupport" (without the quotation marks)
          Double-click the MS Software Library icon
          Find the appropriate product area
          Locate and Download MFCINP32.EXE
    
  • Microsoft Download Service (MSDL)

          Dial (206) 936-6735 to connect to MSDL
          Download MFCINP32.EXE (size: 25194 bytes) 
    

    For additional information about downloading, please see the following article in the Microsoft Knowledge Base:

       ARTICLE-ID: Q119591
       TITLE     : How to Obtain Microsoft Support Files from Online Services
    
    
    NOTE: The App Wizard in Visual C++ version 2.1 and above does generate an inproc OLE Automation server.

    MORE INFORMATION

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

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

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

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

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

      c. Select the OLEAutomation check box.

      d. 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 that 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 reference words: 2.00 3.00
    KBCategory: kbole kbprg kbfile kbcode kbwebcontent
    KBSubcategory: LeTwoAto
    Keywords : LeTwoAto kbcode kbfile kbole kbprg kbwebcontent
    Technology : kbMfc
    Version : 2.03 2.00
    Platform : NT WINDOWS


    THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

    Last reviewed: October 10, 1997
    © 1998 Microsoft Corporation. All rights reserved. Terms of Use.