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

Howdy: I wrote a dll in VB and I have a perl script that is calling it. In the dll I build a Scripting.Dictionary and I want to return it to the Perl script. I cannot get this to work for the life of me. The following is the VB method that I a trying to call:

Public Function returnScriptingObj1() As Object Dim tot As Object Dim debugFile As Integer debugFile = FreeFile Open "d:\debug1.txt" For Output As #debugFile Print #debugFile, "TEST" Set tot = CreateObject("Scripting.Dictionary") tot.Add "tom", "daddy" tot.Add "Ginger", "mommy" tot.Add "Caroline", "kiddy" Close #debugFile Set returnScriptingObj1 = tot 'returnScriptingObj1 = tot End Function

The following is the Perl code:
my $newObj = Win32::OLE->new("TestArray.PArray"); my $resultsArray; #= Variant(VT_BYREF, Variant(VT_EMPTY)); $resultsArray = $newObj->returnScriptingObj1(); print Dumper($resultsArray);<br>
The following is the output from the perl code above:
$VAR1 = bless( { 'Item' => undef, 'Count' => 3, 'CompareMode' => 0 }, 'Win32::OLE' );
First is it possible to get the Scripting.Dictionary object back to the Perl script? If so, what is missing?
Please help...
Thanks, Tom

Edit: added <code> tags. larsen

Replies are listed 'Best First'.
Re: Returning a VB ScriptingObject to Perl app
by Jenda (Abbot) on May 24, 2002 at 14:33 UTC

    Yeah, that's exactly what I would expect. The VB method returned you an Object ... which gets wrapped by Win32::OLE as a Perl Win32::OLE object.

    And as such it cannot be displayed by Data::Dumper.

    You should use it as an object and that should be fine.

    Try

    print $resultsArray->{tom}; or print $resultsArray ->Item(tom);
    and so forth. If you want to print all items in the Dictionary you may use the in() function contained in Win32::OLE :
    use Win32::OLE qw(in); foreach my $key (in $resultsArray) { print $key, " => ", $resultsArray->{$key}, "\n"; }

      Jenda

Re: Returning a VB ScriptingObject to Perl app
by sparkyichi (Deacon) on May 24, 2002 at 12:09 UTC
    Would #= comment out the rest of the line?

    Sparky
    FMTEYEWTK