Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions

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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

On Microsoft Windows, if  when you click or type the name of a .pl file, you get an error "is not recognized as an internal or external command, operable program or batch file", then this means you do not have the .pl file extension associated with …
A year or so back I was asked to have a play with MongoDB; within half an hour I had downloaded (http://www.mongodb.org/downloads),  installed and started the daemon, and had a console window open. After an hour or two of playing at the command …
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…

856 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