Gurusamy Sarathy > libwin32-0.191 > Win32::OLE::Const

Download:
libwin32-0.191.zip

Dependencies

Annotate this POD

CPAN RT

New  9
Open  0
View/Report Bugs
Source  

NAME ^

Win32::OLE::Const - Extract constant definitions from TypeLib

SYNOPSIS ^

    use Win32::OLE::Const 'Microsoft Excel';
    printf "xlMarkerStyleDot = %d\n", xlMarkerStyleDot;

    my $wd = Win32::OLE::Const->Load("Microsoft Word 8\\.0 Object Library");
    foreach my $key (keys %$wd) {
        printf "$key = %s\n", $wd->{$key};
    }

DESCRIPTION ^

This modules makes all constants from a registered OLE type library available to the Perl program. The constant definitions can be imported as functions, providing compile time name checking. Alternatively the constants can be returned in a hash reference which avoids defining lots of functions of unknown names.

Functions/Methods

use Win32::OLE::Const

The use statement can be used to directly import the constant names and values into the users namespace.

    use Win32::OLE::Const (TYPELIB,MAJOR,MINOR,LANGUAGE);

The TYPELIB argument specifies a regular expression for searching through the registry for the type library. Note that this argument is implicitly prefixed with ^ to speed up matches in the most common cases. Use a typelib name like ".*Excel" to match anywhere within the description. TYPELIB is the only required argument.

The MAJOR and MINOR arguments specify the requested version of the type specification. If the MAJOR argument is used then only typelibs with exactly this major version number will be matched. The MINOR argument however specifies the minimum acceptable minor version. MINOR is ignored if MAJOR is undefined.

If the LANGUAGE argument is used then only typelibs with exactly this language id will be matched.

The module will select the typelib with the highest version number satisfying the request. If no language id is specified then a the default language (0) will be preferred over the others.

Note that only constants with valid Perl variable names will be exported, i.e. names matching this regexp: /^[a-zA-Z_][a-zA-Z0-9_]*$/.

Win32::OLE::Const->Load

The Win32::OLE::Const->Load method returns a reference to a hash of constant definitions.

    my $const = Win32::OLE::Const->Load(TYPELIB,MAJOR,MINOR,LANGUAGE);

The parameters are the same as for the use case.

This method is generally preferrable when the typelib uses a non-english language and the constant names contain locale specific characters not allowed in Perl variable names.

Another advantage is that all available constants can now be enumerated.

The load method also accepts an OLE object as a parameter. In this case the OLE object is queried about its containing type library and no registry search is done at all. Interestingly this seems to be slower.

EXAMPLES ^

The first example imports all Excel constants names into the main namespace and prints the value of xlMarkerStyleDot (-4118).

    use Win32::OLE::Const ('Microsoft Excel 8.0 Object Library');
    print "xlMarkerStyleDot = %d\n", xlMarkerStyleDot;

The second example returns all Word constants in a hash ref.

    use Win32::OLE::Const;
    my $wd = Win32::OLE::Const->Load("Microsoft Word 8.0 Object Library");
    foreach my $key (keys %$wd) {
        printf "$key = %s\n", $wd->{$key};
    }
    printf "wdGreen = %s\n", $wd->{wdGreen};

The last example uses an OLE object to specify the type library:

    use Win32::OLE;
    use Win32::OLE::Const;
    my $Excel = Win32::OLE->new('Excel.Application', 'Quit');
    my $xl = Win32::OLE::Const->Load($Excel);

AUTHORS/COPYRIGHT ^

This module is part of the Win32::OLE distribution.

syntax highlighting: