There are two ways to obtain Win32::API Prototype. You can either download and install it
manually from our FTP site:
This will automatically download and install the latest version.
This module mimicks calling the Win32 API from C by allowing a script to
specify a C function prototype.
- ApiLink( $Module, $Prototype, [\@ParameterTypes, $ReturnType] )
-
Declares a Win32 API prototype. There are two ways to call this:
- a) Traditional Win32::API
-
The $Prototype is the name of the Win32 API function and the
second and third parameters are traditional Win32::API parameter and return
types such as:
ApiLink( 'kernel32.dll', 'FindFirstVolume', [P,N], N ) || die;
- b) Prototype style
-
The $Prototype is the actual C prototype of the function as
in:
ApiLink( 'kernel32.dll', 'HANDLE FindFirstVolume(LPTSTR lpszVolumeName, DWORD chBufferLength)' ) || die;
This will create a global function by the same name of the Win32 API
function. Therefore a script can call it as a C program would call the
function.
Example:
use Win32::API::Prototype;
@Days = qw(
Sun
Mon
Tue
Wed
Thu
Fri
Sat
);
ApiLink( 'kernel32.dll', 'void GetLocalTime( LPSYSTEM lpSystemTime )' ) || die;
$lpSystemTime = pack( "S8", 0,0,0,0,0,0,0,0 );
# This function does not return any value
GetLocalTime( $lpSystemTime );
@Time{ year, month, dow, day, hour, min, sec, mil } = unpack( "S*", $lpSystemTime );
printf( "The time is: %d:%02d:%02d %s %04d.%02d.%02d\n", $Time{hour}, $Time{min}, $Time{sec}, $Days[$Time{dow}], $Time{year}, $Time{month}, $Time{day} );
- AllocMemory( $Size )
-
This function will allocate a buffer of $String bytes. The string will be filled with NULL charcters. This is the
equivilent of the C++ code:
LPBYTE pBuffer = new BYTE [ dwSize ];
if( NULL != pBuffer )
{
ZeroMemory( pBuffer, dwSize );
}
Example:
use Win32::API::Prototype;
$pBuffer = AllocMemory( 256 );
- NewString( $String | $Size )
-
This function will create either a string containing $String or create an empty string $Size characters in length. Regardless of what type of string is created it will
be created for UNICODE or ANSI depending on what the Win32 API function
will expect.
Example:
use Win32::API::Prototype;
ApiLink( 'kernel32.dll', 'DWORD GetCurrentDirectory( DWORD nBufferLength, LPTSTR lpBuffer )' ) || die;
$nBufferLength = 256;
$lpBuffer = NewString( $nBufferLength );
# GetCurrentDirectory() returns the length of the directory string
$Result = GetCurrentDirectory( $nBufferLength, $lpBuffer );
print "The current directory is: " . CleanString( $lpBuffer ) . "\n";
- CleanString( $String )
-
This function will clean up and return the passed in $String. This means that the any trailing NULL characters will be removed and if
the string is UNICODE it will be converted to ANSI.
Example:
Refer to the NewString() example.
This site has been hit 7,609,443 times since May 22, 2001
Copyright © 1996 - 2008 Roth Consulting.
Last updated 2004.11.06
.NET, Perl, Python, script, scripting, VB, Visual Basic, java, javascript, perlscript, odbc, database, SQL, Win32, NT, Windows, coding, programing, c, c++, c#,
Linux, Microsoft, IBM, Windows, Exchange, Outlook, Oracle, Sybase,
Windows XP, SP2, Windows Server 2003,
consult, consulting, Dave Roth, David Roth, Adminmisc, Perms, Daemon, Pipe, book, extensions,
IT, administration,
Microsoft Office, Microsoft Word, Microsoft Excel, Microsoft Powerpoint,
security, anti virus, antivirus, firewall, NAT,
WMI, COM, MOM, administration, IT,
network, DSL, Cable, Dial-up, phone, telephone, long distance,
Tablet PC, tabletpc, tablet pcs, tablet pc questions, tablet pc faqs, tablet pc comparisons, tablet pc reviews, Windows XP Tablet PC Edition, popular tablet pc software, Windows XP Tablet PC, utilities, tablet pc games, tabletpc software, tablet pc utilities, windows tablet software
desktop computer, notebook, notebook computer, computer,