Manpage of OLE::lib::Win32::OLE::Const
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};
}
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_]*$/".
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.
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);