Re[2]: [PHP-GTK] Editable tables and general planning help
| From: | Tom Rogers | Date: | Mon, 11 Jul 2005 07:48:42 +0000 |
| Subject: | Re[2]: [PHP-GTK] Editable tables and general planning help | ||
| References: | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 | Groups: | php.gtk.general |
| Request: | Send a blank email to php-gtk-general+get-5944@lists.php.net to get a copy of this message | ||
Hi,
Monday, July 11, 2005, 2:41:27 PM, you wrote:
GM> Hi Tom!
GM> What you done with the clipboard is very interesting!
GM> Could you send me the sources for your php_win32api?
GM> I'm trying to do some "strange" things with the api and it could be in
GM> help for me.
GM> Thanks in advance.
GM> Regards,
GM> Gonzalo.
You can download the source from:
http://kwiktemplates.com/w32api.zip
just unzip in the php ext directory.
The main changes were made to get rid of a crash with a large number
of arguments, deal with complex data types and added callbacks.
Here is a bit of useless code that demonstrates the added bits by
starting a thread in windows to run a function. If the function did
anything useful it would crash as php memory can't be shared between
processes.
<?php
dl("php_w32api.dll");
$api =& new win32;
if(!$api->defineType("SECURITY_ATTRIBUTES { byte &Length; TEST_TYPE
&SecurityDescriptor; bool InheritHandle; }")){
echo "Type SECURITY_ATTRIBUTES failed.\n";
}
$api->registerfunction("long CreateThread
Alias CreateThread
(
SECURITY_ATTRIBUTES &ThreadAttributes,
long dwStackSize,
cb StartAddress, //new type, name of registered callback
long &Parameter,
long dwCreationFlags,
long &ThreadId
)
From kernel32.dll");
$api->registerfunction("long CloseHandle
Alias CloseHandle
(
long hObject
)
From kernel32.dll");
$api->registerfunction(" bool GetExitCodeThread
(
long hThread,
long &ExitCode
)
From kernel32.dll");
// a function to be called by the thread routine
function callback($test=false){
static $state = 'Start';
if(!$test){
$state = 'Called'; //called from thread
}else{
return $state; //called locally
}
echo "Callback called by thread.\n";
return 0;
}
// register the function as a callback
$api->registercallback("long callback()");
$ThreadAttributes = $api->InitType('SECURITY_ATTRIBUTES');
$ThreadAttributes->Length = $api->GetTypeSize('SECURITY_ATTRIBUTES'); //set size of
struct
$dwStackSize = 0;
$StartAddress = 'callback';
$Parameter = false;
$dwCreationFlags = 0;
$ThreadId = 0;
//$api->test('callback');
echo "Starting thread \n";
$ret =
$api->CreateThread($ThreadAttributes,$dwStackSize,$StartAddress,$Parameter,$dwCreationFlags,$ThreadId);
$x=0;
while(($x<5)){
$x++;
echo callback(1)."\n";
sleep(1);
}
echo "function returned:$ret pid:$ThreadId\n";
$ExitCode = -1;
$ret2 = $api->GetExitCodeThread($ret,$ExitCode);
echo "Thread returned $ret2 with exit $ExitCode\n";
$api->CloseHandle($ret);
?>
--
regards,
Tom