PerlCtrl - Return Types

Posted on 2004-09-15
Last Modified: 2007-12-19
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

Question by:holli
LVL 13

Accepted Solution

gripe earned 500 total points
ID: 12064913
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


Author Comment

ID: 12065060
>>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.


LVL 18

Expert Comment

ID: 12069694
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.

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

There are many situations when we need to display the data in sorted order. For example: Student details by name or by rank or by total marks etc. If you are working on data driven based projects then you will use sorting techniques very frequently.…
Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now