SAMPLE: MFCARRAY Using Safe Arrays in MFC Automation

Last reviewed: October 10, 1997
Article ID: Q140202

The information in this article applies to:
  • Microsoft Visual C++, 32-bit Edition, versions 4.0, 5.0
  • Microsoft OLE libraries included with: - Microsoft Windows NT versions 3.5, 4.0 - Microsoft Windows 95

SUMMARY

MFCARRAY is an MFC OLE Automation server application that demonstrates the use of safe arrays. The array is passed to and returned from automation methods in a VARIANT.

Microsoft Visual C++ 5.0 was used to create the automation server. Vb.vbp and Vb.frm in the sample are Visual Basic 5.0 files that can be used to control the automation server.

The following file is available for download from the Microsoft Software Library:

 ~ Mfcarray.exe (size: 44187 bytes) 

For more information about downloading files from the Microsoft Software Library, please see the following article in the Microsoft Knowledge Base:

   ARTICLE-ID: Q119591
   TITLE     : How to Obtain Microsoft Support Files from Online Services

After downloading the file, use the following command to extract the sample and build the appropriate directory structure:

   MFCARRAY.EXE -d

MORE INFORMATION

MFCARRAY implements the following methods:

  • SlowSort: Sorts an input safearray of BSTRs and returns the sorted array and the time required for the sort. The array is passed by reference because it needs to be modified by the sort. SlowSort uses SafeArrayGetElement and SafeArrayPutElement to gain access to the array elements.
  • FastSort: Sorts an input safearray of BSTRs as does SlowSort but uses SafeArrayAccessData to get a pointer to the array elements. This allows direct access to the array elements instead of using SafeArrayGetElement and SafeArrayPutElement. This accounts for the speed improvement over SlowSort.
  • Average: Finds the average of an input safe array of integers. The array is not passed by reference.
  • GetArray: Creates and returns a safe array of BSTRs.

REFERENCE

For an example of referencing the values that are in a VARIANT that contains a SAFEARRAY in an MFC client, please see the following article in the Microsoft Knowledge Base:

   ARTICLE-ID: Q167668
   TITLE     : HOWTO: Pass a SafeArray of Strings in a VARIANT*
Keywords          : LeTwoAt
Technology        : kbole
Version           : WINDOWS:4.0; WINDOWS NT:5.0,4.0,3.5;
Platform          : NT WINDOWS
Issue type        : kbfile
Solution Type     : kbsample


================================================================================


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.