Returning dynamic array from C++ DLL to VB

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • CK938
    New Member
    • Jul 2007
    • 4

    Returning dynamic array from C++ DLL to VB

    Hi,

    I was hoping someone could help me return a dynamic array from a C++ Dll to VB.

    Here's a simple example.

    Code:
    double * TestFunction(int count)
    {
         double* temp = new double[count];
    
         for (int i = 0; i < count; i++){
              temp[i] = i;
         }
    
         return temp;
    }

    Basically I want to return an array that holds more than 1 value back to VB.
    Is there a better way to do this?
    Perhaps using a void function and somehow passing in the pointer by ref?

    Any help will be much appreciated.


    Thanks.
  • MyOpic
    New Member
    • Feb 2008
    • 1

    #2
    Originally posted by CK938
    Hi,

    I was hoping someone could help me return a dynamic array from a C++ Dll to VB.

    Here's a simple example.

    Code:
    double * TestFunction(int count)
    {
         double* temp = new double[count];
    
         for (int i = 0; i < count; i++){
              temp[i] = i;
         }
    
         return temp;
    }

    Basically I want to return an array that holds more than 1 value back to VB.
    Is there a better way to do this?
    Perhaps using a void function and somehow passing in the pointer by ref?

    Any help will be much appreciated.


    Thanks.
    You need to convert your array to a safearray then return it back to VB
    see the following link:
    http://support.microso ft.com/kb/177218

    Comment

    Working...