package Win32::Resource;

BEGIN {
    die "The Win32::Resource module works only on Windows NT"
	unless Win32::IsWinNT();
}

use strict;
use vars qw($VERSION @ISA);
use DynaLoader;

$VERSION = '0.11';
@ISA = qw(DynaLoader);


sub AddFiles {
    my $exeName = shift;
    return 1 unless @_;
    my %hash = @_;
    my $count = 101;

    my $handle = BeginUpdateResource($exeName);
    foreach my $key (keys %hash) {
	my $data;
	local $/;
	open(RES, "<$hash{$key}") or die "Unable to open $hash{$key}: $!\n";
	binmode RES;
	$data = <RES>;
	close RES;
	UpdateResource($handle, $key, 'ANAME', $count);
	UpdateResource($handle, $data, 'ADATA', $count);
	++$count;
    }
    EndUpdateResource($handle);
}

sub AddLibraries {
    my $exeName = shift;
    return 1 unless @_;
    my %hash = @_;
    my $count = 101;

    my $handle = BeginUpdateResource($exeName);
    foreach my $key (keys %hash) {
	my $data;
	local $/;
	open(RES, "<$hash{$key}") or die "Unable to open $hash{$key}: $!\n";
	binmode RES;
	$data = <RES>;
	close RES;
	print "Adding Binary: $hash{$key}\n";
	UpdateResource($handle, $key, 'LIBNAME', $count);
	UpdateResource($handle, $data, 'LIBRARY', $count);
	++$count;
    }
    EndUpdateResource($handle);
}

bootstrap Win32::Resource;

1;
__END__

=pod

=head1 NAME

Win32::Resource::Bind - bind resources to modules in perl

=head1 SYNOPSIS

    use Win32::Resource;
  
    Win32::Resource::Bind($Script, $binmodule, $exeName, $resName, $resID)


=head1 DESCRIPTION

This module offers binding of additional resource types to specific modules.


=head1 NAME

Win32::Resource::BuildOEM - bind resources to a named executable

=head1 SYNOPSIS

    use Win32::Resource;
  
    Win32::Resource::BuildOEM($exeName, $baseName, \%scripts)

    $exeName - the name of the executable to modify
    $baseName - the string that will be used as the base string in registry lookups
    %scripts - a reference to a hash of the scripts. The keys are the relative names
		values are the scripts themselves.

=head1 DESCRIPTION

This module offers binding of additional resource types to specific modules.

=head1 FUNCTIONS

=head2 Win32::Resource::UpdateVersion($exeName, $sv)
    
    Where
        $exeName is the path name of the executable.
        $sv is a reference to a hash.

    The hash is filled with the keys:

	"comments"
	"companyname"
	"filedescription"
	"fileversion"
	"internalname"
	"legalcopyright"
	"legaltrademarks"
	"originalfilename"
	"productname"
	"productversion"
	"filenumber"
	"productnumber"


=head2 Win32::Resource::GetVersionInfo($exeName, $sv)

    Where
        $exeName is the path name of the executable.
        $sv is a reference to a hash.

    The hash is filled with the keys:

	"comments"
	"companyname"
	"filedescription"
	"fileversion"
	"internalname"
	"legalcopyright"
	"legaltrademarks"
	"originalfilename"
	"productname"
	"productversion"
	"filenumber"
	"productnumber"

    This is the same hash as the function 
    Win32::Resource::UpdateVersion($exeName, $sv)

=cut

