Microsoft KB Archive/107546

= DOC: Collect.exe - OLE Automation Collection =

Article ID: 107546

Article Last Modified on 8/9/2004

-

APPLIES TO

 Microsoft OLE 2.03 Microsoft OLE 4.0, when used with:  Microsoft Windows NT 4.0

 Microsoft Windows NT 3.51 Service Pack 5

 Microsoft Windows 95 </li></ul>

-

<div class="notice_section">

This article was previously published under Q107546

<div class="summary_section">

SUMMARY
Collect.exe demonstrates how to create an OLE automation collection object.

<div class="moreinformation_section">

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

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

The collection object implements the following methods and properties: Add Method, Count Property, Item Property, NewEnum Property, and Remove Method.

Error handling in the collection object involves raising exceptions. CreateStdDispatch does not allow exceptions to be raised, so the collection object implements the IDispatch interface using DispGetIDsOfNames and DispInvoke.

Add Method
<pre class="fixed_text">Description:    Adds the indicated item to the collection. If an object is created, it should be returned. Arguments:      Varies. It can be a pointer to the object that is to be                added or it can the information required to create the object. Return type:    Varies. If no object is created, the return type should be void. If an object is created, the return type should be VT_DISPATCH. NOTE: The Add method is not appropriate for all collections, so it is not required. For many application-created collections, objects are automatically added to the collection for the user.

Count Property
<pre class="fixed_text">Description:    Returns the number of items in the collection. Read-only property. Arguments:      None. Return type:    VT_I4.

Item Property
<pre class="fixed_text">Description:    Returns the indicated item in the collection. Argument:       Specifies the index. Some collections allow various types of indexing. For example, this sample allows an integer or                string to be specified as an index. Return type:    VT_DISPATCH. NOTE: Item is the default value for the object, so it should have the special DISPID, DISPID_VALUE. MkTypLib automatically assigns this DISPID if the default attribute is specified in the ODL file.

_NewEnum Property
<pre class="fixed_text">Description:    Returns an enumerator that supports IEnumVariant for the items currently in the collection. Read-only property. Arguments:      None. Return type:    VT_UNKNOWN. NOTE: NewEnum will not be accessible to users and must have the restricted attribute in the ODL file. The NewEnum method must have a special DISPID, DISPID_NEWENUM. The defining characteristic of a collection is the ability for a user to iterate over the items in it. Some languages will have built- in support for collections. The NewEnum method allows an OLE automation controller to support "for each" iteration over a collection: For Each Item In Collection Debug.Print Item.Text Next Item OLE automation controllers that support "for each" iteration will call the NewEnum method on the collection object and then QueryInterface on the resulting IUnknown to get the desired IEnumVariant.

Remove Method
<pre class="fixed_text">Description:    Removes the specified item from the collection. Argument:       Specifies the index. Some collections allow various types of indexing. For example, this sample allows an integer or string to be specified as an index. Return type:    void. NOTE: The object is not deleted. It is simply removed from the collection. Remove should support the same kinds of indexing as the Item method for the same collection. The Remove method is not appropriate for all collections, so it is not required. For many application-created collections, objects are automatically removed the collection for the user.

To Run
The collection sample application object exposes the following: ProgID : Collection.Application <pre class="fixed_text">  Method and Property Names     Notes ---  [App Object] Collection (read only prop)  Returns empty collection. New Item   (method)          Creates and returns new item.

[Item Object] Text       (default prop)    Sets and returns string.

[Collection Object] See above for exposed properties and methods. Update the path in HELLO.REG to the current location of the object and the type libraries.

To Compile
Requires OLE version 2.01 or later.

Include device=vmb.386 in the [386Enh] section of SYSTEM.INI.

NOTE: vmb.386 can be found in \OLE2\BIN. Run WXSERVER.EXE from \OLE2\BIN before running the makefile.

Additional query words: AutoCtrl Collect

Keywords: kbinfo kbdownload kbdocfix kbfile kbautomation kbsample KB107546

-

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

© Microsoft Corporation. All rights reserved.