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"); }


=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

Who is Participating?
gripeConnect With a Mentor Commented:
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:


(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.


Matt Shaw

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.


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.


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.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.