通过php调用windows api
通过php调用windows 系统的dll 里的api
首先去php.net 下载php4.2.3 win32 版本. 因为要用到一个函数只有php4.2.0-php4.2.3才支持
主要下载 installer就可以.然后去下载一个php_w3api.dll 放到和php.exe同目录下
php.exe同目录下新建一个test.php文件
写入代码:
<?php
dl("php_w32api.dll");
w32api_register_function("kernel32.dll","GetTickCount","long");
w32api_register_function("User32.dll","MessageBoxA","long");
$ticks = GetTickCount();
$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.",
$ticks,
$secs,
$mins,
$hours,
$mins - ($hours*60));
MessageBoxA(NULL,
$str,
"Uptime Information",0);
?>
然后 运行输入 cmd 进入php.exe所在目录 输入 php.exe test.php
那么可以看到 将弹出一个系统的弹出框,显示你电脑的开机运行时间。截图如下
用的例子是手册上的..其他api调用方法相同...先从dll注册函数 然后调用.注意参数的类型。
php5.1 以后该api已经被移除了 据说是无人维护..实用性不是很大..仅供参考研究..
转载于:https://my.oschina.net/jiuxiaoyao/blog/76601