SAMPLE: MFCARRAY Using Safe Arrays in MFC Automation
ID: Q140202
|
The information in this article applies to:
-
Microsoft Visual C++, 32-bit Editions, versions 4.0, 5.0, 6.0
-
Microsoft OLE Libraries, used with:
-
Microsoft Windows NT, versions 3.5, 4.0
-
Microsoft Windows 95
-
Microsoft Windows 2000
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
Download Center. Click the file name below to download the file:
MFCArray.exe For more information about how to download files from the Microsoft
Download Center, please visit the Download Center at the following Web
address
http://www.microsoft.com/downloads/search.asp
and then click How to use the Microsoft Download Center.
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:
Q167668 HOWTO: Pass a SafeArray of Strings in a VARIANT
Additional query words:
Keywords : kbfile kbsample kbAutomation kbNTOS351 kbNTOS400 kbWinOS2000 kbOLE200 kbVC400 kbVC500 kbVC600 kbWinOS95 kbGrpCom kbDSupport LeTwoAt
Version : winnt:3.5,4.0,5.0,6.0; :
Platform : winnt
Issue type : kbhowto
|