SAMPLE: MFCINP16: Inproc 16-bit MFC Automation Object

Last reviewed: October 10, 1997
Article ID: Q130843
2.03 1.52 WINDOWS kbole kbprg kbfile

The information in this article applies to:

  • Microsoft OLE version 2.03
  • Microsoft Foundation Classes (MFC) included with Microsoft Visual C++ for Windows, version 1.52

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 in the Microsoft Software Library, is a 16-bit inproc automation object that was created using the steps in this article.

You can find MFCINP16.EXE (size: 48563 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 MFCINP16.EXE (size: 48563 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 MFCINP16.EXE (size: 48563 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 MFCINP16.EXE
    
  • Microsoft Download Service (MSDL)

          Dial (206) 936-6735 to connect to MSDL
          Download MFCINP16.EXE (size: 48563 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
    
    

    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 shows you how.

    Steps to Create a 16-Bit Inproc Automation Object in MFC

    It is assumed that Visual C++ version 1.51 or greater 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 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.)

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

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

    5. 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. Complet the following steps:

      a. Select the OLE Automation tab in the MFC 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
            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.)
      

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

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

    8. Build the project. Register the inproc Automation object by choosing RegisterControl from the Tools menu.

    9. VB.MAK and VB.FRM in the sample are Visual Basic version 3.0 files that you can use to control the object.


  • Additional reference words: 2.03 1.52
    KBCategory: kbole kbprg kbfile
    KBSubcategory: LeTwoAto
    Keywords : LeTwoAto kbfile kbole kbprg
    Technology : kbMfc
    Version : 2.03 1.52
    Platform : 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.