I added an Automation object to the application I am working on. This allows our clients using Visual Basic to access our application's functionality easily. Everything works fine except when I want to pass arrays of data between a Visual Basic application and my MFC application. The type of the Variant is VT_ARRAY as expected but the dimension and the element size are random values.
I added a method to my CCmdTarget-derived class using Class Wizard. This gives...
BOOL CApplication::GetDoubleArray(const VARIANT FAR& varArray)
// Make sure the input value in an array
ASSERT(vType & VT_ARRAY);
if (vType & VT_ARRAY)
// Things do not work as expected starting from here...
// lDim and lElemSize are never OK (They seem to be random.)
// Show that lDim and lElemSize are random values
strMsg.Format("lDim=%d lElemSize=%d", lDim, lElemSize);
[id(3)] boolean GetDoubleArray(VARIANT varArray);
in the ODL file.
On Visual Basic side, the code is...
Dim MyObj As Object
Set MyObj = CreateObject("MyObj.Application")
Dim dArray() As Long
ReDim dArray(0 To 10)
I have the same problem with in-process and out-of-process Automation servers.
If I add the same method in an ActiveX Control, everything works fine!
Any help will be appreciated.