Perl Sample: Acquire and save to BMP file
The following Perl 5.x example script is all that is required to do the following:
Note that this example assumes Perl is running in a 32-bit environment. For 64-bit Perl, use DTWAIN64.DLL or DTWAIN64U.DLL instead of DTWAIN32.DLL. #!/usr/bin/perl use strict; use warnings; $|++; use Win32::API;
# DTWAIN Constants. See DTWAIN32.PL file for these values use constant DTWAIN_BMP => 100; use constant DTWAIN_USELONGNAME => 16; use constant DTWAIN_USENATIVE => 1; use constant DTWAIN_PT_DEFAULT => 1000;
# DTWAIN function definitions. See DTWAIN32.PL for these settings my $DTWAIN_IsTwainAvailable = new Win32::API('DTWAIN32.DLL','DTWAIN_IsTwainAvailable','','N'); my $DTWAIN_SysInitialize = new Win32::API('DTWAIN32.DLL','DTWAIN_SysInitialize','','N'); my $DTWAIN_SelectSource = new Win32::API('DTWAIN32.DLL','DTWAIN_SelectSource','','N'); my $DTWAIN_SysDestroy = new Win32::API('DTWAIN32.DLL','DTWAIN_SysDestroy','','N'); my $DTWAIN_AcquireFile = new Win32::API('DTWAIN32.DLL','DTWAIN_AcquireFile','NPNNNNNNP','N');
# Start to use the DTWAIN functions my $isAvail = $DTWAIN_IsTwainAvailable->Call(); if ( $isAvail == 1 ) { my $return = $DTWAIN_SysInitialize->Call(); if ( $return != 0 ) { my $TwainSource = $DTWAIN_SelectSource->Call(); if ( $TwainSource != 0 ) { $DTWAIN_AcquireFile->Call($TwainSource, 'test.bmp', DTWAIN_BMP, DTWAIN_USENATIVE + DTWAIN_USELONGNAME, DTWAIN_PT_DEFAULT, 1, 1, 1, 0); } } $DTWAIN_SysDestroy->Call(); } Note that the Win32::API Perl package must be installed for this example to work, as well as the DTWAIN DLL available on an accessible directory (a directory specified on your system PATH). Also note that this program doesn't test if the DTWAIN DLL file exists or if the functions within the DLL exists, so an appropriate Perl die or warn should be used in a production program to ensure that there are no DLL or functional issues.
The constants and function prototypes are included in the file DTWAIN32.PL, DTWAIN32U.PL, DTWAIN64.PL and DTWAIN64U.PL. Please use the version that matches the Perl environment you are running (either 32-bit or 64-bit). |