Win32::kernel32 - Experimental interface to some of the KERNEL32.DLL functions
use Win32::kernel32; # or use Win32::kernel32 qw( Sleep CopyFile GetVolumeInformation );
Syntax:
Win32::Beep ( [FREQUENCY, DURATION] )
Plays a simple tone on the speaker; FREQUENCY is expressed in hertz and ranges from 37 to 32767, DURATION is expressed in milliseconds. Note that parameters are relevant only on Windows NT; on Windows 95, parameters are ignored and the system plays the default sound event (or a standard system beep on the speaker if you have no sound card).
FREQUENCY
DURATION
Example:
Win32::Beep(440, 1000);
Win32::CopyFile ( SOURCE, TARGET, [SAFE] )
Copies the SOURCE file to TARGET. By default, it fails if TARGET already exists; to overwrite the already existing file, the SAFE flag must be set to 0. Returns a true value if the operation was successfull, a false one if it failed.
SOURCE
TARGET
SAFE
if(Win32::CopyFile($from, $to)) { print "Copy OK.\n"; } else { # overwrite the already existing file if(Win32::CopyFile($from, $to, 0)) { print "Copy OK, file replaced.\n"; } else { print "Copy failed.\n"; } }
Win32::GetBinaryType ( FILENAME )
Returns the type ot the executable file FILENAME. Possible values are:
FILENAME
0 A Win32 based application 1 An MS-DOS based application 2 A 16-bit Windows based application 3 A PIF file that executes an MS-DOS based application 4 A POSIX based application 5 A 16-bit OS/2 based application
If the function fails, undef is returned.
undef
Note: this function is available on Windows NT only.
print "Notepad is a type ", Win32::GetBinaryType("c:\\winnt\\notepad.exe"), "\n";
Win32::GetCompressedFileSize ( FILENAME )
Returns the compressed size of the specified FILENAME, if the file is compressed; if it's not compressed, it returns the normal file size (eg. same as -s).
-s
print Win32::GetCompressedFileSize("c:\\documents\\longlog.txt");
Win32::GetCommandLine ( )
Returns the complete command line string, including the full path to the program name and its arguments.
print Win32::GetCommandLine();
Win32::GetCurrencyFormat ( NUMBER, [LOCALE] )
Returns NUMBER formatted to your locale's currency settings. You can optionally supply a different LOCALE for foreign currencies.
NUMBER
LOCALE
print "You owe me ", Win32::GetCurrencyFormat(rand()*10000), "\n"; # ten millions italian lires... $LotOfMoney = Win32::GetCurrencyFormat(10000000, 1040); # 1040 is "Italian (Standard)" (see also VerLanguageName) # and it returns: L. 10.000.000
Win32::GetDiskFreeSpace ( [ROOT] )
Returns the amount of free disk space on the drive indicated by ROOT; if this is omitted, uses the current drive. To specify a drive, you must provide the exact root directory (eg. for drive C: it must be: "C:\"). In a scalar context, it returns the number of free bytes; in a list context, it returns the number of free bytes and the total number of bytes on the disk.
ROOT
$free = Win32::GetDiskFreeSpace("c:\\"); ($free, $total) = Win32::GetDiskFreeSpace();
Win32::GetDriveType ( [ROOT] )
Returns the type ot the drive indicated by ROOT. If this is omitted, uses the current drive. To specify a drive, you must provide the exact root directory (eg. for drive C: it must be: "C:\"). Possible return values are:
0 The drive type cannot be determined 1 The root directory does not exist 2 The disk can be removed from the drive 3 The disk cannot be removed from the drive 4 The drive is a remote (network) drive 5 The drive is a CD-ROM drive 6 The drive is a RAM disk
print "C: is a type ", Win32::GetDriveType("c:\\"), "\n";
Win32::GetTempPath ( )
Returns the path of the directory designated for temporary files, or undef on errors.
print "Please put your temp files in ", Win32::GetTempPath(), "\n";
Win32::GetVolumeInformation ( [ROOT] )
Returns a 5-elements array with some information about the drive indicated by ROOT. If this is omitted, uses the current drive. Typically used as follows:
($label, $serial, $maxlen, $flags, $fstype) = Win32::GetVolumeInformation();
Here are the meaning of the fields:
label the volume label serial the volume serial number maxlen the maximum filename length, in chars, supported by the volume flags a set of flags associated with the file system fstype the type of the file system (such as FAT or NTFS)
For more information about the flags field, please refer to the GetVolumeInformation() documentation in the Microsoft Win32 SDK Reference.
flags
If called in a scalar context, the function returns only the first element (the volume label).
$volume = Win32::GetVolumeInformation(); print "Working on $volume...";
Win32::MultiByteToWideChar ( STRING, [CODEPAGE] )
Converts a STRING in Unicode format. The additional CODEPAGE parameter can have one of this values:
STRING
CODEPAGE
0 ANSI codepage 1 OEM codepage 2 MAC codepage
Or the number of a codepage installed on your system (eg. 850 for "MS-DOS Multilingual (Latin I)"). The default, if none specified, is the ANSI codepage. Returns the converted string or undef on errors.
$UnicodeString = Win32::MultiByteToWideChar($string);
Win32::QueryPerformanceCounter ( )
Retrieves the current value of the high-resolution performance counter, if it exists. Returns zero if it doesn't. To see how many times per second the counter is incremented, use QueryPerformanceFrequency().
$freq = Win32::QueryPerformanceFrequency(); $count1 = Win32::QueryPerformanceCounter(); # do something $count2 = Win32::QueryPerformanceCounter(); print ($count2-$count1)/$freq , " seconds elapsed.\n";
Win32::QueryPerformanceFrequency ( )
Returns the frequency of the high-resolution performance counter, if it exists. Returns zero if it doesn't. See also QueryPerformanceCounter.
QueryPerformanceCounter
Win32::SearchPath ( FILENAME )
Search for the specified FILENAME in the path. The following directories are searched:
1. the directory from which the application loaded. 2. the current directory 3. the Windows system directory 4. the Windows directory 5. the directories in the PATH environment variable
Returns the full path to the found file or undef if the file was not found.
print "Notepad exists" if -f Win32::SearchPath("notepad.exe");
Win32::SetLastError ( VALUE )
Sets the Win32 last error to the specified VALUE.
VALUE
# reset pending errors Win32::SetLastError(0);
Win32::Sleep ( MILLISECONDS )
Sleeps for the number of MILLISECONDS specified.
MILLISECONDS
# sleep for 1/2 second Win32::Sleep(500);
Win32::VerLanguageName ( LOCALE )
Returns a descriptive string for the language associated with the specified LOCALE.
$ITA = Win32::VerLanguageName(1040); $JAP = Win32::VerLanguageName(1041);
Win32::WideCharToMultiByte ( STRING, [CODEPAGE] )
Converts an Unicode STRING to a non-Unicode one. The additional CODEPAGE parameter can have one of this values:
$string = Win32::WideCharToMultiByte($UnicodeString);
GetSystemTime => [[P], V], QueryDosDevice => [[P, P, N], N],
Aldo Calpini ( dada@perl.it ).
Cosimo Streppone, <cosimo@cpan.org>
To install Win32::API, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Win32::API
CPAN shell
perl -MCPAN -e shell install Win32::API
For more information on module installation, please visit the detailed CPAN module installation guide.