HOWTO: Return Array to VB from VC++ DLL or OLE ServerLast reviewed: November 25, 1997Article ID: Q177218 |
The information in this article applies to:
SUMMARYThis article illustrates how to return an array from a Microsoft Visual C++ DLL or OLE server using the ColeSafeArray class included with the Microsoft Foundation Classes (MFC).
MORE INFORMATIONYou can receive, manipulate, and return Microsoft Visual Basic arrays in Microsoft Visual C++ with an understanding of safe arrays. A safe array is an array that contains information about the number of dimensions and the bounds of its dimensions. Because Microsoft Visual Basic natively uses these types of arrays, you have to construct safe arrays of the data you want to pass. Normally, this is a difficult task, and hard to manage from Microsoft Visual C++. However, this task is easier if you use the ColeSafeArray class included with the Microsoft Foundation Classes. The following DLL routine demonstrates how to use this class to return a 10x10 two-dimensional array of doubles from a DLL. NOTE: The same code and principles in this sample DLL also apply to an OLE server.
Steps to Create the Visual C++ DLL
Steps to Create the Visual Basic Program That Uses the DLL
Other NotesRun-time error 5 "Invalid Procedure Call" or run-time error 11 "Divide by zero" may occur when performing this task. Error 5 often occurs when calling into an OLE server whose method was not properly created. To correct this error, re-create this method using ClassWizard, choose the appropriate options, and then cut and paste the code into your new function. If Error 11 occurs while attempting to access elements in your array, it may indicate that you did not construct the safe array correctly. It might not have been completely initialized or it could have been corrupted from logical errors in your code. To resolve this error, verify that you are not indexing the array past its bounds, or overwriting memory.
REFERENCESMore information about the ColeSafeArray class, or VARIANT types, is included in the Microsoft Visual C++ online help, and/or MSDN. Keywords : VBKBAutomation Technology : kbole Version : WINDOWS:4.0,5.0; WINNT:4.0,5.0 Platform : WINDOWS winnt Issue type : kbhowto Solution Type : kbsample |
================================================================================
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |