Delicious Bookmark this on Delicious Share on Facebook SlashdotSlashdot It! Digg! Digg

PHP : Function Reference : W32api Functions

W32api Functions


This extension is a generic extension API to DLLs. This was originally written to allow access to the Win32 API from PHP, although you can also access other functions exported via other DLLs.

Currently supported types are generic PHP types (strings, booleans, floats, integers and nulls) and types you define with w32api_deftype().


This extension has been moved to the » PECL repository and is no longer bundled with PHP as of PHP 5.1.0.


This extension is EXPERIMENTAL. The behaviour of this extension -- including the names of its functions and anything else documented about this extension -- may change without notice in a future release of PHP. Use this extension at your own risk.


This extension will only work on Windows systems.


There is no installation needed to use these functions; they are part of the PHP core.

Runtime Configuration

This extension has no configuration directives defined in php.ini.

Resource Types

This extension defines one resource type, used for user defined types. The name of this resource is "dynaparm".

Predefined Constants

The constants below are defined by this extension, and will only be available when the extension has either been compiled into PHP or dynamically loaded at runtime.

DC_MICROSOFT (integer)
DC_BORLAND (integer)
DC_CALL_CDECL (integer)
DC_CALL_STD (integer)
DC_RETVAL_MATH4 (integer)
DC_RETVAL_MATH8 (integer)
DC_CALL_STD_BO (integer)
DC_CALL_STD_MS (integer)
DC_CALL_STD_M8 (integer)
DC_FLAG_ARGPTR (integer)


This example gets the amount of time the system has been running and displays it in a message box.

Example 2611. Get the uptime and display it in a message box

// Define constants needed, taken from
// Visual Studio/Tools/Winapi/WIN32API.txt
define("MB_OK", 0);

// Load the extension in

// Register the GetTickCount function from kernel32.dll
// Register the MessageBoxA function from User32.dll

// Get uptime information
$ticks = GetTickCount();

// Convert it to a nicely displayable text
$secs  = floor($ticks / 1000);
$mins  = floor($secs / 60);
$hours = floor($mins / 60);

$str = sprintf("You have been using your computer for:" .
"\r\n %d Milliseconds, or \r\n %d Seconds" .
"or \r\n %d mins or\r\n %d hours %d mins.",
$mins - ($hours*60));

// Display a message box with only an OK button and the uptime text
"Uptime Information",

Table of Contents

w32api_deftype — Defines a type for use with other w32api_functions
w32api_init_dtype — Creates an instance of the data type typename and fills it with the values passed
w32api_invoke_function — Invokes function funcname with the arguments passed after the function name
w32api_register_function — Registers function function_name from library with PHP
w32api_set_call_method — Sets the calling method used

Code Examples / Notes » ref.w32api


The win32 support appears to be pretty flaky in php. This of course is to be expected with an experimental extension. That being said, if you are having trouble using the win32 functionality you may want to look into creating a PHP extension instead.
We were having some problems interfacing PHP with a 3rd party dll. As such we created an extension which wraps the interface with the aforementioned dll. The solution was surprisingly quick and painless.
Because we use Delphi primarily we found the following extremely useful and easy to use.
more info here:


The w32api extension -does not- work on versions of php that are not between 4.2.0 and 4.2.3. This is mentioned on the individual function's manual pages, but not on the extension's main page. Perhaps I'm just missing something, but if you want to interact with the Win32 API via PHP you have to use an outdated version, or just not bother with it at all.

23-aug-2003 09:42

The small, unofficial documentation is now available here .
The old link from the post above is dead.
Note that the W32API doesn't seem to be under development anymore. E-Mails to the author stayed unanswered.
If you really have to use it, just some hints here: There are often problems concerning Apache webservers. This extension doesn't seem to work with mod_php.
I used the API on IIS5 with PHP as CGI. Additionally the IUSR_<hostname> (that's the user IIS runs php.exe by default) might need additional rights to be able to call certain API-functions.


The only way I've been able to call Win32 API functions with PHP5 has been through COM and DynamicWrapper.
Get DynamicWrapper at:
(remove new line)
Here's an example to play a beep sound with your computer speaker:
$com = new COM("DynamicWrapper");
$com->Register("KERNEL32.DLL", "Beep", "i=ll", "f=s", "r=l");
$com->Beep(5000, 100);

jan kleinsorge

Or google for "win32.hlp". Almost every API-function is listed in there.


It seems that this extension will be replaced by FFI extension in PHP5. FFI stands for "Foreign Function Interface" and it's not limited by Windows API, but also supports Linux APIs. You may reach this extension's website at . For Windows, you may try this code from commandline php.exe:
dl ("php_ffi.dll");
$windows = new ffi ("[lib='user32.dll'] int MessageBoxA( int handle, char *text, char *caption, int type );" );
echo $windows->MessageBoxA(0, "Message For You", "Hello World", 1);

philip soeberg

In response to post by Jan Kleinsorge.
To get the proper windows system uptime, one should use the Performance Monitoring system... GetTickCount is limited to 49.7 days, as the result is a dword.
if (!dl("php_w32api.dll")) {
 echo "Unable to load php_w32api.dll";
$api = new win32;
$api->registerfunction("bool QueryPerformanceCounter (float &lpPerformanceCount) From kernel32.dll");
$api->registerfunction("bool QueryPerformanceFrequency (float &lpPerformanceFrequency) From kernel32.dll");
$c = $a/$b;
$days = floor($c / 86400);
echo gmstrftime("System uptime is $days Days, %H Hr, %M Min, %S Sec
", $c);
The above snippet will return the true uptime for an unlimited time for a windows OS. (Disregarding the fact that windows needs reboot every 10 days or so :))
A tiny dange though is the lack of 64bit variable types in php.. (the "float &lpPerformanceCount" should be "long long &lpPerformanceCount") .. Nevertheless.. It works :)
Philip S.


In order to use most (perhaps all?) of the win32 API while running with a web server you have to give the server service permission to interact with the desktop.  This is especially noticeable with the given example, where the script will try to display message boxes on the server's display.
Keep in mind, however, that you should think hard about the consequences of letting a web server interact with your desktop, especially if you're not the only one using the web server.


I played a bit around with the W32API. Here is some code that actually works with the current release of W32API.
The interface changed completely, so all documentation about this extension is out-dated. While the old release
just implemented "plain" functions, the current version offers a class to handle all the API-related operations.
Additionally, functions are now registered using a SQL-like language with a single string.
$api = new win32;
    BOOL GetUserName(
       LPTSTR lpBuffer, // address of name buffer
       LPDWORD nSize   // address of size of name buffer
   Returns the current thread's username
   "&" passes argument as "refrence" not as "copy"
$api->registerfunction("long GetUserName (string &a, int &b) From advapi32.dll");
   DWORD GetTickCount(VOID)
   Returns the ms the OS is running
$api->registerfunction("long GetTickCount () From Kernel32.dll");
$len = 255;                   // set the length your variable should have
$name = str_repeat("\0", $len); // prepare an empty string
if ($api->GetUserName($name, $len) == 0)
if (!($time = $api->GetTickCount()))
echo "Username: $name
\nSystemtime: $time
Jan Kleinsorge


for phpgtk users, who might want to add some sound to their apps, here is the code, assuming ding.wav is in the script's directory
$api = new win32;
$api->registerfunction("long sndPlaySound (string a, int b) From winmm.dll");
$api->sndPlaySound("ding.wav", 0);
you can use the big win32.hlp file containing the win32 api reference to get some other multimedia functions

sami fouad

Here is a new link for the official page for the Windows API @ Microsoft's site:


Answer to the note posted by me at nullflux dot com (see below)
The Win32 API *does* work in other versions of PHP than between 4.2.0 and 4.2.3. However the documented functions are not available. You will have to use the "win32" class to access functions. For an example, read Philip Soeberg's post just below.

sami fouad contains functions for use with this extension.
Beware! The menu system is very dense, and confusing at first if you don't know where your going.
Luckily for you I am going to add how to get there in this note. ;)
Windows Development > Development Guides > Windows API > Windows API Reference

Change Language

Follow Navioo On Twitter
.NET Functions
Apache-specific Functions
Alternative PHP Cache
Advanced PHP debugger
Array Functions
Aspell functions [deprecated]
BBCode Functions
BCMath Arbitrary Precision Mathematics Functions
PHP bytecode Compiler
Bzip2 Compression Functions
Calendar Functions
CCVS API Functions [deprecated]
Class/Object Functions
Classkit Functions
ClibPDF Functions [deprecated]
COM and .Net (Windows)
Crack Functions
Character Type Functions
Cybercash Payment Functions
Credit Mutuel CyberMUT functions
Cyrus IMAP administration Functions
Date and Time Functions
DB++ Functions
Database (dbm-style) Abstraction Layer Functions
dBase Functions
DBM Functions [deprecated]
dbx Functions
Direct IO Functions
Directory Functions
DOM Functions
DOM XML Functions
enchant Functions
Error Handling and Logging Functions
Exif Functions
Expect Functions
File Alteration Monitor Functions
Forms Data Format Functions
Fileinfo Functions
filePro Functions
Filesystem Functions
Filter Functions
Firebird/InterBase Functions
Firebird/Interbase Functions (PDO_FIREBIRD)
FriBiDi Functions
FrontBase Functions
FTP Functions
Function Handling Functions
GeoIP Functions
Gettext Functions
GMP Functions
gnupg Functions
Haru PDF Functions
hash Functions
Hyperwave Functions
Hyperwave API Functions
i18n Functions
IBM Functions (PDO_IBM)
iconv Functions
ID3 Functions
IIS Administration Functions
Image Functions
Imagick Image Library
Informix Functions
Informix Functions (PDO_INFORMIX)
Ingres II Functions
IRC Gateway Functions
PHP / Java Integration
JSON Functions
LDAP Functions
libxml Functions
Lotus Notes Functions
LZF Functions
Mail Functions
Mailparse Functions
Mathematical Functions
MaxDB PHP Extension
MCAL Functions
Mcrypt Encryption Functions
MCVE (Monetra) Payment Functions
Memcache Functions
Mhash Functions
Mimetype Functions
Ming functions for Flash
Miscellaneous Functions
mnoGoSearch Functions
Microsoft SQL Server Functions
Microsoft SQL Server and Sybase Functions (PDO_DBLIB)
Mohawk Software Session Handler Functions
mSQL Functions
Multibyte String Functions
muscat Functions
MySQL Functions
MySQL Functions (PDO_MYSQL)
MySQL Improved Extension
Ncurses Terminal Screen Control Functions
Network Functions
Newt Functions
NSAPI-specific Functions
Object Aggregation/Composition Functions
Object property and method call overloading
Oracle Functions
ODBC Functions (Unified)
ODBC and DB2 Functions (PDO_ODBC)
OpenAL Audio Bindings
OpenSSL Functions
Oracle Functions [deprecated]
Oracle Functions (PDO_OCI)
Output Control Functions
Ovrimos SQL Functions
Paradox File Access
Parsekit Functions
Process Control Functions
Regular Expression Functions (Perl-Compatible)
PDF Functions
PDO Functions
Phar archive stream and classes
PHP Options&Information
POSIX Functions
Regular Expression Functions (POSIX Extended)
PostgreSQL Functions
PostgreSQL Functions (PDO_PGSQL)
Printer Functions
Program Execution Functions
PostScript document creation
Pspell Functions
qtdom Functions
Rar Functions
GNU Readline
GNU Recode Functions
RPM Header Reading Functions
runkit Functions
SAM - Simple Asynchronous Messaging
Satellite CORBA client extension [deprecated]
SCA Functions
SDO Functions
SDO XML Data Access Service Functions
SDO Relational Data Access Service Functions
SESAM Database Functions
PostgreSQL Session Save Handler
Session Handling Functions
Shared Memory Functions
SimpleXML functions
SNMP Functions
SOAP Functions
Socket Functions
Standard PHP Library (SPL) Functions
SQLite Functions
SQLite Functions (PDO_SQLITE)
Secure Shell2 Functions
Statistics Functions
Stream Functions
String Functions
Subversion Functions
Shockwave Flash Functions
Swish Functions
Sybase Functions
TCP Wrappers Functions
Tidy Functions
Tokenizer Functions
Unicode Functions
URL Functions
Variable Handling Functions
Verisign Payflow Pro Functions
vpopmail Functions
W32api Functions
WDDX Functions
win32ps Functions
win32service Functions
xattr Functions
xdiff Functions
XML Parser Functions
XML-RPC Functions
XMLReader functions
XMLWriter Functions
XSL functions
XSLT Functions
YAZ Functions
YP/NIS Functions
Zip File Functions
Zlib Compression Functions
eXTReMe Tracker