Hi all,
 
I hope that somebody can help me with a problem that I am having while returning a 1D Safearray to a Perl client from an OLE component, everything is OK when the array has some elements, but if the array is empty I get the following error:
 
Win32::OLE(0.1704) error 0x8002000b: "Invalid index"
 
I am using Active State Perl Version 5.8.8, Build 819. I am testing under windows XP, service pack 2, and I am building my OLE interface with Visual Studio 6, SP6.
 
I have created a cut-down COM object to test the problem, its interface supports IDispatch and is OLE Automation compatible. In the IDL file the test method is declared as:
   
[id(1), helpstring("method GetArray")] HRESULT GetArray([in] int elementCount, [out, retval] VARIANT* pV);
 
This method returns a SAFEARRAY in a Variant, the elementCount argument indicates how many elements should be placed in the array before it is returned.
 
This is how GetArray() is defined, it creates a Safearray of type VT_I4:
 
STDMETHODIMP CTestOutArray::GetArray(int elementCount,
                                                                  VARIANT *pV)
{
   V_VT(pV)= VT_ARRAY | VT_I4;
 
   SAFEARRAYBOUND saBound;
   saBound.lLbound = 0;
   saBound.cElements = elementCount;
 
   SAFEARRAY* pA = SafeArrayCreate(VT_I4, 1, &saBound);
   V_ARRAY(pV) = pA;
 
   if (elementCount > 0)
   {
    long val = 1234;
    for (long i = 0; i< elementCount; i++)
     SafeArrayPutElement(pA, &i, &i);
   }
 
   return S_OK;
}
 
I have got rid of any error checking code etc. to make it a bit easier to read...
 
When I call this from Perl with elementCount > 0, everything works OK, but when I call it with elementCount == 0 I get the 'Invalid Index' error.
   
Here is the client Perl Code:
 
use strict;
 
use Win32::OLE qw(in with);
$Win32::OLE::Warn = 3;
 
my $test = Win32::OLE->new('PerlOutArrayTest.TestOutArray', 'Quit') or die "Couldn't create object";
 
my $arr = $test->GetArray(1); # Works OK
my $second_arr = $test->GetArray(0); # Throws an error
 
Can anybody spot if I am doing something wrong? Should Perl work OK when an OLE method returns an empty Safearray, or should I just expect it to throw this error when the array is empty?
 
It's all a bit of a pain as I sometimes need to return an empty array as part of normal operation, and I don't want to have to add loads of nasty extra code handle  the situation as an error...
 
Any help would be greatly appreciated, thanks for reading!
 
Kevin Godden.

Send instant messages to your online friends http://uk.messenger.yahoo.com

_______________________________________________
Perl-Win32-Users mailing list
Perl-Win32-Users@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to