pecl-php-ffi

Foreign Function Interface

Stars
11
Committers
10

$Id$

Usage:

First you need to declare the functions and types that you will be using:

$win32_idl <<<EOD [lib='kernel32.dll'] DWORD GetTickCount(); [lib='user32.dll'] int MessageBoxA(int handle, char *text, char *caption, int type); EOD;

Then bind those into an ffi context:

$ffi = new ffi($win32_idl);

And then use it:

$count = $ffi->GetTickCount(); echo $ffi->MessageBoxA(0, "The tick count is " . $count, "Ticky Ticky", 1);

Structures:

You can declare structures in your ffi IDL using C style syntax. Structure support is read-only for the moment. You can pass structures to functions and return them (these two examples work on linux):

Passing structs:

Returning Structs:

Tips:

For functions that expect to copy/store memory into a buffer, use str_repeat() to "allocate" room for that buffer.

vim:tw=78:et