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

I'm new to using Win32::OLE and I've run into a problem. The application I want to interface with (SpaceObServer from JAM Software) has the following method I am trying to use:

Syntax (nasty VBS!)

GetFileAgesValue (FolderID : <Integer>, Index : <Shortint>, OccupiedSpace : <OLEVariant>, NumFiles : <OLEVariant>)

Parameters

FolderID The ID referring to the directory for which the "Age of Files" values should be retrierved. You get this ID from the functions RootFolderID, FirstChildID or NextSiblingID.

Index The index of the "Age of Files" bar to export. The first index is always 0. The last index is always (FileAgesCount-1)

OccupiedSize (Out Parameter) The space occupied by all files of this "Age of Files" interval.

NumFiles (Out Parameter) The number of files of this "Age of Files" interval.

My code fragment for calling this method is:
$AllocSpace = 0; $NumbFiles = 0; my $SOS = Win32::OLE->GetActiveObject("SpaceObServer.Application") || Win32::OLE->new("SpaceObServer.Application", 'Quit'); # get already + active SOS # application or open new for($i=0; $i < $SOS->{FileAgesCount}; $i++) { $SOS->{ROOTDirectory} = $RootDirectory; $CurrentID = $SOS->{RootFolderID}; $SOS->GetFileAgesValue({ olderID => $CurrentID, Index => $i, OccupiedSize => $AllocSpace, NumFiles => $NumbFiles }); print "$AllocSpace\n\n"; # Just to see if I get any data returned }
Setting the first 2 parameters is no problem but how to I get at the returned values? In VBScript the parameters are positional and I just Dim the variables and present the names.

From a confused BasilOfWestdene

Replies are listed 'Best First'.
Re: Using Win32::OLE
by Corion (Patriarch) on Jun 26, 2012 at 13:23 UTC

    I can't conveniently test it, but likely, you can use Win32::OLE::Variant for the OUT types:

    my $NumbFiles = Variant(VT_EMPTY); $SOS->GetFileAgesValue({ ... NumFiles => $NumbFiles, }); ... print $NumbFiles;
      Hi Corion,

      Thanks for the idea but I'm still getting nothing returned - and I've tried multiple Variant options including VT_BYREF. I'm not sure the call is working properly (I've tried dumping the method and I get 2 undef variables.

      BasilOfwesdene
Re: Using Win32::OLE
by bulk88 (Priest) on Jun 26, 2012 at 15:30 UTC
    If you didn't know already, use OLEView and look at the IDL http://www.sapnet.ru/examples/oleview_typelib.gif . For your specific problem, a variant is used when the data can be a string/floating/point/array and the API wants to deliver all versions of it. Corion's post is probably right. If it can be done in VB AND you can find example code of it in VB, it can be done with Win32::OLE. The only limitation to Win32::OLE is when you use IUnknown interfaces, which are C only interfaces. Win32::OLE only supports IDispatch interfaces. A IUnknown interface, must be called using C on machine code level. An IDispatch interface internally, briefly described, is what in Perl is calls eval. Also, if you want to see if you truly have any data in those scalars, Data::Dumper for the light viewing and Devel::Peek for hard core viewing. I googled up GetFileAgesValue, that last 2 are probably intergerish. Also do "Win32::OLE->Option(Warn => 3);" in your code, you never checked if GetFileAgesValue succeeded.
      Sorry it's take so long to reply (holidays and work got in the way!). Nothing I've tried has worked but I had to move on and the easiest way was to just to call a vbs script via the command interface. Thanks for your efforts. Barry.
        Sorry it's take so long to reply (holidays and work got in the way!).
        Are you trying to set a record for longest time OP's reply to answer for OP's OP? jkjk