Solved

PerlCtrl - Return Types

Posted on 2004-09-15
3
463 Views
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"); }

=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
Comment
Question by:holli
3 Comments
 
LVL 13

Accepted Solution

by:
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:

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
 
LVL 6

Author Comment

by:holli
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.

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
 
LVL 18

Expert Comment

by:kandura
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.
0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
read PayflowPro reports using the report metadata using perl 11 44
To run CGI/perl on tomcat and connect to oracle database. 5 146
parse a file and get data out 11 103
perl syntax 3 29
I have been pestered over the years to produce and distribute regular data extracts, and often the request have explicitly requested the data be emailed as an Excel attachement; specifically Excel, as it appears: CSV files confuse (no Red or Green h…
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…

740 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