Win32-Resources
view release on metacpan or search on metacpan
lib/Win32/Resources.pm view on Meta::CPAN
package Win32::Resources;
use strict;
use warnings;
require Exporter;
our @ISA = qw(Exporter);
our %EXPORT_TAGS = ( 'all' => [ qw(
LoadResource
) ] );
our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } );
our $VERSION = '0.02';
require XSLoader;
XSLoader::load('Win32::Resources', $VERSION);
sub LoadResource {
my $param = $_[0];
if (not ref $param) { $param = {@_}; }
$param = _check_param($param);
return undef unless ($param);
$param->{language} = defined($param->{language}) ? Win32::Resources::_MakeLangId($param->{language}) : Win32::Resources::_MakeLangId();
return _LoadResource(
$param->{filename} || '',
$param->{type},
$param->{name},
$param->{language},
);
}
sub _check_param {
my ($param) = @_;
if ($param->{file}) {
open(F, "<$param->{file}") or return undef;
binmode(F);
{ local $/; $param->{data} = <F>; }
close(F);
}
if (defined($param->{path})) {
($param->{type}, $param->{name}, $param->{language}) = split m#/#, $param->{path};
}
$param->{type} = _get_rt($param->{type});
return undef unless ($param->{name});
return undef unless ($param->{type});
$param->{name} = uc($param->{name});
$param->{type} = uc($param->{type});
if ($param->{name} =~ /^\d+$/) {
$param->{name} = int($param->{name});
}
if ($param->{type} =~ /^\d+$/) {
$param->{type} = int($param->{type});
}
if (defined($param->{language}) and ($param->{language} =~ /^\d+$/)) {
$param->{language} = int($param->{language});
}
return $param;
}
sub _get_rt {
my ($name) = @_;
my $rt = {
RT_CURSOR => 1,
RT_BITMAP => 2,
RT_ICON => 3,
RT_MENU => 4,
RT_DIALOG => 5,
RT_STRING => 6,
RT_FONTDIR => 7,
RT_FONT => 8,
RT_ACCELERATOR => 9,
RT_RCDATA => 10,
RT_MESSAGETABLE => 11,
DIFFERENCE => 11,
RT_GROUP_CURSOR => 12, # (RT_CURSOR + DIFFERENCE)
RT_GROUP_ICON => 14, # (RT_ICON + DIFFERENCE)
RT_VERSION => 16,
RT_DLGINCLUDE => 17,
RT_PLUGPLAY => 19,
RT_VXD => 20,
RT_ANICURSOR => 21,
RT_ANIICON => 22,
RT_HTML => 23,
};
if (defined($rt->{$name})) {
return $rt->{$name};
} elsif (defined($rt->{"RT_$name"})) {
return $rt->{"RT_$name"};
} else {
return $name;
}
}
1;
( run in 1.414 second using v1.01-cache-2.11-cpan-71847e10f99 )