• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 608
  • Last Modified:

ATL COM object returns readable array with VBA but type mismatch with VBScript?

I have a COM object I wrote using Visual Studio 5 ATL.

It has a property whose get method returns an array of Doubles.

I can read the array just fine when I call it from a Visual Basic or VBA container.

But when I try to get the property using VBScript, using the WSH.WScript engine, I get a Type Mismatch error when I try to access it.

I ran the COM project in Debug mode using the VBScript in WSH as the driver, and I verified that it is returning an array (SAFEARRAY) of doubles values, but the values aren't visible to the driver. Again, this only happens in VBScript, but not straight VB or VBA.
0
jtm111
Asked:
jtm111
  • 4
  • 2
1 Solution
 
mrblueCommented:
Just idea:  try to pass parameter as VARIANT (VT_R8|VT_ARRAY).

I guess that there can be some limitation on parameter type.
0
 
mrblueCommented:
If it doesn't work you can alternatively add some accessor method:
GetArrayVal([in] short Index, [out, retval] double *Val)
0
 
jtm111Author Commented:
mrblue, hopefully that's what I'm doing: the return type is VARIANT *pVal and I'm inserting the array in the pVal->vt

pVal->vt = VT_ARRAY | VT_R8;

then I'm packing a SAFEARRAY

      psa = SafeArrayCreate(VT_R8, 1, &bounds); // 1 = 1 dimension

      double* transfer_buff;  // send data back as a double
      SafeArrayAccessData(psa, reinterpret_cast<void**>(&transfer_buff));

      // pack the cutpoints into the transfer buffer
      for (i = 0; i < num_bin_boundaries; i++)
            transfer_buff[i] = cutpoints[i];

      SafeArrayUnaccessData(psa);
      pVal->parray = psa;

and I return pVal.

0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
mrblueCommented:
By the way check error code if any.
0
 
mrblueCommented:
I don't know if VT_ARRAY | VT_R8 can be accessed in VBScript but

VT_ARRAY | VT_VARIANT works without problem (at least for 1 dimentional array).

-----
pVal->vt = VT_ARRAY |  VT_VARIANT;

     psa = SafeArrayCreate(VT_VT_VARIANT, 1, &bounds); // 1 = 1 dimension

     CComVariant* transfer_buff;  // send data back as a double
     SafeArrayAccessData(psa, reinterpret_cast<void**>(&transfer_buff));
      transfer_buff[0] = 102.0;   // CComVariant class handles conversion
----

Note that if you create array in VBScript it's type will be Variant()  (TypeName() function)
 
0
 
jtm111Author Commented:
thanks mrblue, your solution worked perfectly.
0

Featured Post

Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

  • 4
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now