Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 506
  • Last Modified:

PerlCtrl - Return Types

How do i return an array from a PerlCtrl Function?
this is what i have:

use strict;

package PerlControl;

sub returnArray { return ("a", "b", "c"); }

=pod

=begin PerlCtrl

    %TypeLib = (
        PackageName     => 'PerlControl',

        # DO NOT edit the next 3 lines.
        TypeLibGUID     => '{b6d529e0-184d-4ab2-8c9e-57b7a4585c01}',
        ControlGUID     => '{b4b03048-470b-4402-9638-71a3077bb9c3}',
        DispInterfaceIID=> '{2a120f89-cf5d-4507-b6e7-9bedf137b87f}',

        ControlName     => 'HelloWorldControl',
        ControlVer      => 1,   # increment if new object with same ProgID
        ProgID          => 'PerlControl.HelloWorld',
        DefaultMethod   => '',

        Methods         => {
            'returnArray' => {
                    RetType             =>  VT_BSTR,  #what do i have to specify here to return an array of BSTR
                    TotalParams         =>  0,
                    NumOptionalParams   =>  0,
                    ParamList           =>[ ]  
                },
                        
            },  # end of 'Methods'



        Properties      => {
            }
        ,  # end of 'Properties'
        );  # end of %TypeLib

=end PerlCtrl


0
holli
Asked:
holli
1 Solution
 
gripeCommented:
Based on the content of your post, I can only guess that you're using PerlCtrl to create a perl object to be exposed to another language, such as VB. The return types you are defining in your %TypeLibs hash are the return types for the language you're exposing to. (IE: VB) The ActiveState documentation for the Perl Resource Kit shows the following valid variant datatypes:

Type Name                       Type Symbol
Unspecified                       VT_EMPTY
Null                                  VT_NULL
2-byte Signed Integer        VT_I2  
4-byte Signed Integer        VT_I4
4-byte Real Value              VT_R4
8-byte Real Value              VT_R8
Currency                          VT_CY
Date                                VT_DATE
Binary String                    VT_BSTR
IDispatch FAR*                 VT_DISPATCH
Scodes                            VT_ERROR
Boolean                           VT_BOOL
Variant FAR*                   VT_VARIANT
IUnknown FAR*               VT_UNKNOWN
Unsigned char                 VT_UI1

My understanding is that to return an array to VB you would follow your required datatype with a pipe and VT_ARRAY such as:

RetType => VT_DATATYPE | VT_ARRAY

(Where DATATYPE is a valid type from the list above.)

This should do what you require.

As an addendum, perl subroutines always return 'lists'. Which can be applied to scalars, arrays or hashes as necessary.

Hope this helps.

References:

http://aspn.activestate.com/ASPN/Mail/Message/pdk/619689
http://www.mail-archive.com/activeperl@listserv.activestate.com/msg13708.html


Matt Shaw
http://www.thinktechnology.ca/

0
 
holliAuthor Commented:
>>I can only guess that you're using PerlCtrl to create a perl object to be exposed to another language, such as VB.

correct.

surfing the aspn mailing list i just found that out by myself.
This is a very basic issue it should REALLY be mentioned in the PDKs Docs shouldn´t it?

anyway, you are right, you get the points.

tx,

holli
0
 
kanduraCommented:
The ParamList is just there for the benefit of consumers of your COM object. It will tell them which parameters (and of which type) this method accepts.

I mean that when you view the object's typelib in e.g. the OLE Browser, you will see something to the effect of

    interface HelloWorld : IDispatch {
        VT_BSTR returnArray( ParamName1 VT_I4, ParamName2 VT_BSTR )
    }

In Visual Studio the Code Completion would also show something like that. When you add your object to the toolkit and when you use the object, call the method, then the VS compiler will check the arguments against your typelib definition.

Of course, perl is not very fussy about type or the number of arguments to functions, so you have more flexibility that in e.g. C#.
Nonetheless, it may be wise to be as strict as possible, and even use prototypes in perl, just to avoid creating undocumented interfaces.
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now