in reply to Where's the result??? (problem with Win32::OLE)

You could try passing $result by reference.
use Win32::OLE::Variant; # ... my $result = Variant(VT_BYREF|VT_BSTR); my $return = $registry->GetStringValue(2147483650, $strPath, $strV +alue, $result);
$result will still be a Win32::OLE::Variant object, but it should stringify correctly to the returned value.

Replies are listed 'Best First'.
Re: Re: Where's the result??? (problem with Win32::OLE)
by jpavel (Sexton) on Mar 26, 2003 at 20:52 UTC
    jand, my hero. You're right, of course. I actually had to use:
    my $result = Variant(VT_BYREF|VT_BSTR,0);
    But there it is! Thank you!
Re: Re: Where's the result??? (problem with Win32::OLE)
by jpavel (Sexton) on Mar 26, 2003 at 21:22 UTC
    Anyone want to take this on? I'm not that fluent with OLE::Variants, but in order to capture registry keys, you need to pass an array. For instance, to get all the subkeys under "HKEY_Users"...
    $base = ''; my @keys = Variant(VT_ARRAY|VT_UI1, ''); $result = $registry->EnumKey(2147483651, $base, @keys); print "$base\nResult: $result\n"; foreach $key (@keys) { print "Key:$key\n"; }
    I _thought_ this would propogate with the keys. No such luck. I also tried initializing the blank array to a SID (since that is the length it is going to match) but again, no luck.
      Try this:
      my $keys = Variant(VT_BYREF|VT_VARIANT); my $result = $registry->EnumKey(2147483651, $base, $keys); my @dim = $keys->Dim; for ($dim[0][0] .. $dim[0][1]) { my $key = $keys->Get($_); # ... }
        jand, is there I way I can up your guru score? Again, I had to pass:
        my $keys = Variant(VT_BYREF|VT_VARIANT, 0);
        But that did it! I'm ecstatic to have a solution, but I don't fully understand it... what was wrong with using VT_ARRAY? I don't quite get the Dim function, nor why the array is mulitdimensional (or appears to be... we're going from [0][0] .. [0][1]?). I've probably harassed jand enough... can anyone pose an explanation?
      I'm in a hurry right now, but one thing I can spot immediately: @keys should be $keys, as VARIANTs are always scalars. In this case you have a reference to a SAFEARRAY, not a Perl level array.

      Oh, and another thing: Win32::OLE may be treating one dimensional arrays of VT_UI1 specially, so I'm not sure if this might complicate things some more.