Passing VBA user-defined type to DLL

I have an Excel program that passes parameters to a DLL for use in some calculations. I would like to contain some of these parameters within a Type/struct. The problem is that a couple of the VBA Type members are arrays which vary in size, depending on user inputs. How can I create a struct in my DLL to accept a VBA Type with an array that varies in size?

For instance:
VBA:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
'Omitted DLL call
Private Type VBAoutputs
    arr1() as double
    arr2() as double
End Type

Sub mySub(mArray() as Double)
    arrSize = Ubound(mArray)
    Dim myOutput as VBAoutputs
    ReDim myOutput.arr1(arrSize), myOutput.arr2(arrSize)

    'myDLL takes myOutput by reference, and 
    'augments it with calculated values
    Call myDLL(myOutput, ByVal arrSize as Long)
    'Do some stuff with myOutput members
End Sub


C++ DLL:
1
2
3
4
5
6
7
8
9
10
11
12
struct VBAoutpus
{
    //dynamic arr1
    //dynamic arr2
};

void __stdcall myDLL(VBAoutputs &DLLout, int arrSize)
{
    //use arrSize to size DLLout.arr1 and DLLout.arr2
    //do calculations
    //write data to DLLout.arr1 and DLLout.arr2
}


I had originally fixed the DLL struct array sizes, but I don't want to have the possibility of overflowing the struct arrays or have to restrict the array size on the VBA side.

I would like to use vectors for the struct members, but I don't think I can make a VBA Type member that would accept a vector.

Thanks in advance!
I think you need to look into SAFEARRAYs

Andy

How To Pass Arrays Between Visual Basic and C
http://support.microsoft.com/kb/207931

SAFEARRAY structure
http://msdn.microsoft.com/en-us/library/windows/desktop/ms221482%28v=vs.85%29.aspx
Topic archived. No new replies allowed.