小弟這幾天剛接觸 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的樣子 >@<
謝謝^^