小弟这几天刚接触 PHP 程式,因之前并无学过其他程式
因此在使用上发生了很多的疑问
使用程式为 PHP Designer 2005
PHP程式版本为 Version 4.3.11 支援 WIN32
如果到 PHP函数内可以找到一个为 W32api Functions 的函数
在里面有一个范例
如下 :
<?php
// Define constants needed, taken from
// Visual Studio/Tools/Winapi/WIN32API.txt
define("MB_OK", 0);
// Load the extension in
dl("php_w32api.dll");
// Register the GetTickCount function from kernel32.dll
w32api_register_function("kernel32.dll",
"GetTickCount",
"long");
// Register the MessageBoxA function from User32.dll
w32api_register_function("User32.dll",
"MessageBoxA",
"long");
// 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.",
$ticks,
$secs,
$mins,
$hours,
$mins - ($hours*60));
// Display a message box with only an OK button and the uptime text
MessageBoxA(NULL,
$str,
"Uptime Information",
MB_OK);
?>
小弟努力了很多天都RUN不出来
于是对他进行修修改改~~~
变成下面这个样子
<?php
// Define constants needed, taken from
// Visual Studio/Tools/Winapi/WIN32API.txt
define("MB_OK", 0);
//dl("php_w32api.dll"); <----- 程式原本为此行小弟改成下面那一行
$api = new win32; <----- 修改后的程式
//$api->register_function("kernel32.dll","GetTickCount()","long"); <----- 程式原本为此行小弟改成下面那一行
$api->registerfunction("long GetTickCount() From kernel32.dll"); <----- 修改后的程式
//$api->register_function("User32.dll","MessageBoxA()","long");<----- 程式原本为此行小弟改成下面那一行
$api->registerfunction("long MessageBoxA() from User32.dll"); <----- 修改后的程式
//$ticks = GetTickCount(); "); <----- 程式原本为此行小弟改成下面那一行
$ticks =$api->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.",
$ticks,$secs,$mins,$hours,$mins - ($hours*60));
// Display a message box with only an OK button and the uptime text
//$api->MessageBoxA(NULL, <---- 小弟推测此区应该有一个视窗显示,但是并无
// $str, 法执行,因此先将其注解,使程式不会发生
// "Uptime Information", 错误
// MB_OK); ---->
echo $str; <------小弟新增的,方便确认GetTickCount() 是否有作用
?>
输出结果如下:
You have been using your computer for: 12484671 Milliseconds, or 12484 Secondsor 208 mins or 3 hours 28 mins.
但是如果没将
$api->MessageBoxA(NULL,
$str,
"Uptime Information",
MB_OK);
echo $str;
标记为注解,程式及会发生错误
错误视窗内讯息如下:
PHP.EXE 应用程式错误
"0x003e2acc"指令参考的"0x00000000"记忆体.该记忆体不能为"READ".
请按[确定]终止程式
请按[取消]进行程式侦错
不知道是否有高手可以代为解答一下@@
因为发现很少人用PHP RUN WIN32API的样子 >@<
谢谢^^