Jim has asked for the wisdom of the Perl Monks concerning the following question:

How do I use a function from a homegrown Win32 DLL written in Visual Basic 6 that returns a variant array? I'm using ActivePerl 5.8.8 and Win32::API.

I don't have access to the source code of the DLL or any documentation. I only know it looks like this in the Win32::OLE Browser that comes with ActivePerl:

Library: Foo Class: Bar Function: vntFooBar
The function prototype looks like this:

Function vntFooBar(strFoo As String, strBar As String, lngBaz As Long)
I know the function returns a variant array because its developer told me so, and because its named with the prefix 'vnt'. I just don't know what a variant array is, exactly.

Thanks!

Jim

Replies are listed 'Best First'.
Re: Getting a Variant Array From a Win32 DLL Function
by weismat (Friar) on Oct 29, 2007 at 06:05 UTC
    You need to use Win32::OLE::Variant module.
    Variants are the variable datatype between OLE functions which are a generic type which needs to be casted.
    You will need to use Dim() and Get(DIM) to get the elements and need to convert them according to their types to use them.
      Thank you for your reply.

      I had stumbled upon Win32::OLE::Variant, but I was and still am confounded by it and by its relationship to Win32::API.

      I have a DLL, but I don't know that it's an "OLE server". Can I use Win32::OLE::Variant in tandem with Win32::API? If so, how?

      Here's the documentation of Win32::OLE::Variant->Dim():

      Returns a list of array bounds for a VT_ARRAY variant. The list contains an array reference for each dimension of the variant's SAFEARRAY. This reference points to an array containing the lower and upper bounds for this dimension.

      Working backwards from that, which I don't grok, into a working Perl script seems daunting. Is it hopeless?

      I confess I thought using Perl to do a tad bit of Windows programming was going to be easier.

      Jim