SAMPLE: OLE Automation Inproc Object

Last reviewed: August 5, 1996
Article ID: Q107982
The information in this article applies to:
  • Microsoft OLE Libraries for Windows and Win32s, version 2.0
  • Microsoft OLE Libraries, included with:

        - Microsoft Windows NT, versions 3.5 and 3.51
        - Microsoft Windows 95
    

SUMMARY

AUTODLL demonstrates how to create a OLE automation inproc object.

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

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

    AUTODLL implements a OLE automation inproc object (DLL server) called Hello that exposes one property, HelloMessage, and one method, SayHello. It uses an OLE provided IDispatch implementation that is created using CreateStdDispatch.

    The AUTODLL dynamic-link library (DLL) uses the memory allocator used by the calling task. This is required of all inproc objects. The new and delete operators are redefined to use the calling task s memory allocator and all memory management is done using the redefined new and delete.

    The interface that AUTODLL exposes is described using an object description language (HELLO.ODL). The mktyplib tool is used to create a type library (HELLO.TLB) from HELLO.ODL. CreateStdDispatch is then used to implement an IDispatch interface using the interface description in the type library.

    AUTODLL exports DllGetClassObject, which is called by OLE to get the class factory. OLE uses this classfactory to create a Hello object. Automation controllers use the IDispatch interface exposed by the Hello object to access its property and method. AUTODLL also exports DllCanUnloadNow.

    The SIMPAUTO sample in the Software/Data library demonstrates the implementation of an automation object with the same methods and properties as AUTODLL, but which is an EXE. The main differences between the two samples are in the MAIN.CPP file.

    To Run

    The Hello object exposes the following:

       ProgID : SimpleAutomationInProc.Hello
    
       Method & Property Names       Notes
       --------------------------------------------------------------
       HelloMessage  (prop)          Sets and returns string.
       SayHello    (method)          Displays HelloMessage in an edit
                                     control.
    
    
    Update the path in HELLO.REG to the current location of the object and the type library.

    To Compile

    Requires OLE 2.01 or later.

    Include device=vmb.386 in the [386Enh] section of SYSTEM.INI. Note that vmb.386 can be found in \OLE2\BIN. Run the WXSERVER.EXE from \OLE2\BIN before running the makefile.

    Files

    MAIN.CPP    Does initialization, redefines new and delete, implements
                DllGetClassObject, DllCanUnloadNow. and contains code that
                calls CreateStdDispatch.
    HELLO.CPP   Implements the HELLO object.
    
    HELLOCF.CPP Implements the HELLO class factory.
    HELLO.ODL   Object Description Language that describes the property and
                method that HELLO exposes.
    HELLO.H     Defines the HELLO object and the class factory.
    TLB.H       Header file created by mktyplib.
    MAKEFILE    Makefile for project.
    
    VB.MAK,
    VB.FRM      Visual Basic project files to control this sample.
    

  • Additional reference words: 2.00 3.50 4.00 server softlib AUTODLL.EXE
    KBCategory: kbole kbfile kbwebcontent
    KBSubcategory: LeTwoAto


    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: August 5, 1996
    © 1998 Microsoft Corporation. All rights reserved. Terms of Use.