Deprecated: The each() function is deprecated. This message will be suppressed on further calls in /home/zhenxiangba/zhenxiangba.com/public_html/phproxy-improved-master/index.php on line 456
PHP: W32api 関数 - Manual
[go: Go Back, main page]

PHP
downloads | documentation | faq | getting help | mailing lists | reporting bugs | php.net sites | links | conferences | my php.net

search for in the

w32api_deftype" width="11" height="7"/> <vpopmail_set_user_quota
Last updated: Mon, 05 Feb 2007

view this page in

CLXX. W32api 関数

導入

この拡張モジュールは、DLL への一般的な拡張 API です。この拡張モジュールは もともと PHP から Win32 API にアクセスできるようにするために 作成されましたが、他の DLL によりエクスポートされている他の関数にも アクセスすることができます。

現在サポートされている型は、一般の PHP 型 (文字列, boolean, float, 整数, NULL) と w32api_deftype() で定義した型です。

注意: この拡張モジュールは » PECL レポジトリに移動 されており、以下のバージョン以降 PHP にバンドルされなくなっています。 PHP 5.1.0.

警告
この拡張モジュールは、 実験的 なものです。この拡張モジュールの動作・ 関数名・その他ドキュメントに書かれている事項は、予告なく、将来的な PHP のリリースにおいて変更される可能性があります。 このモジュールは自己責任で使用してください。

要件

この拡張モジュールは Windows システムでのみ動作します。

インストール手順

PHP コアに含まれるため、 追加のインストール無しで使用できます。

実行時設定

設定ディレクティブは定義されていません。

リソース型

この拡張モジュールは 1 種類のリソース型を定義し、ユーザ定義型で 使用されます。このリソースの名前は "dynaparm" です。

定義済み定数

以下の定数が定義されています。 この関数の拡張モジュールが PHP 組み込みでコンパイルされているか、 実行時に動的にロードされている場合のみ使用可能です。

DC_MICROSOFT (integer)
DC_BORLAND (integer)
DC_CALL_CDECL (integer)
DC_CALL_STD (integer)
DC_RETVAL_MATH4 (integer)
DC_RETVAL_MATH8 (integer)
DC_CALL_STD_BO (integer)
DC_CALL_STD_MS (integer)
DC_CALL_STD_M8 (integer)
DC_FLAG_ARGPTR (integer)

以下の例は、システムの実行時間を取得し、メッセージボックスに 表示するものです。

例 2427. uptime を取得し、メッセージボックスに表示する

<?php
// 必要な定数を定義します。これは
// Visual Studio/Tools/Winapi/WIN32API.txt から取得できます。
define("MB_OK", 0);

// 拡張モジュールを読み込みます。
dl("php_w32api.dll");

// kernel32.dll の GetTickCount 関数を登録します。
w32api_register_function("kernel32.dll",
                        
"GetTickCount",
                        
"long");
                        
// User32.dll の MessageBoxA 関数を登録します。
w32api_register_function("User32.dll",
                        
"MessageBoxA",
                        
"long");

// uptime 情報を取得します。
$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));

// OK ボタンと uptime のみのメッセージボックスを表示します。
MessageBoxA(NULL,
           
$str,
           
"Uptime Information",
           
MB_OK);
?>

目次

w32api_deftype — 他の w32api_functions で使用するために型を定義する
w32api_init_dtype — データ型 typename のインスタンスを作成し、そこに渡された値を代入する
w32api_invoke_function — 関数名の後ろに指定された引数を指定し、関数 funcname を実行する
w32api_register_function — ライブラリの関数 function_name を PHP に登録する
w32api_set_call_method — 使用するコール方式を設定する


add a note add a note User Contributed Notes
W32api 関数
MagicalTux at FF dot st
17-Feb-2005 01:10
Answer to the note posted by me at nullflux dot com (see below)

The Win32 API *does* work in other versions of PHP than between 4.2.0 and 4.2.3. However the documented functions are not available. You will have to use the "win32" class to access functions. For an example, read Philip Soeberg's post just below.
Sami Fouad
24-Nov-2004 08:37
Here is a new link for the official page for the Windows API @ Microsoft's site:

http://tinyurl.com/5mupk
serdar_soydemir at hotmail dot com
31-May-2004 02:34
It seems that this extension will be replaced by FFI extension in PHP5. FFI stands for "Foreign Function Interface" and it's not limited by Windows API, but also supports Linux APIs. You may reach this extension's website at http://pecl.php.net/package/ffi . For Windows, you may try this code from commandline php.exe:

<?php
dl
("php_ffi.dll");

$windows = new ffi ("[lib='user32.dll'] int MessageBoxA( int handle, char *text, char *caption, int type );" );

echo
$windows->MessageBoxA(0, "Message For You", "Hello World", 1);
?>
chris at ramsoft dot biz
19-May-2004 03:46
The win32 support appears to be pretty flaky in php. This of course is to be expected with an experimental extension. That being said, if you are having trouble using the win32 functionality you may want to look into creating a PHP extension instead.

We were having some problems interfacing PHP with a 3rd party dll. As such we created an extension which wraps the interface with the aforementioned dll. The solution was surprisingly quick and painless.
Because we use Delphi primarily we found the following extremely useful and easy to use. http://users.chello.be/ws36637/php4delphi.html#download

more info here:
http://php.us.themoes.org/manual/en/zend.creating.php
me at nullflux dot com
20-Apr-2004 08:27
The w32api extension -does not- work on versions of php that are not between 4.2.0 and 4.2.3. This is mentioned on the individual function's manual pages, but not on the extension's main page. Perhaps I'm just missing something, but if you want to interact with the Win32 API via PHP you have to use an outdated version, or just not bother with it at all.
Philip Soeberg
20-Jan-2004 01:09
In response to post by Jan Kleinsorge.

To get the proper windows system uptime, one should use the Performance Monitoring system... GetTickCount is limited to 49.7 days, as the result is a dword.

<?php
if (!dl("php_w32api.dll")) {
  echo
"Unable to load php_w32api.dll";
  exit;
}

$api = new win32;
$api->registerfunction("bool QueryPerformanceCounter (float &lpPerformanceCount) From kernel32.dll");
$api->registerfunction("bool QueryPerformanceFrequency (float &lpPerformanceFrequency) From kernel32.dll");

$api->QueryPerformanceCounter($a);
$api->QueryPerformanceFrequency($b);
$c = $a/$b;
$days = floor($c / 86400);
echo
gmstrftime("System uptime is $days Days, %H Hr, %M Min, %S Sec<br>", $c);
?>

The above snippet will return the true uptime for an unlimited time for a windows OS. (Disregarding the fact that windows needs reboot every 10 days or so :))
A tiny dange though is the lack of 64bit variable types in php.. (the "float &lpPerformanceCount" should be "long long &lpPerformanceCount") .. Nevertheless.. It works :)

Philip S.
Jan Kleinsorge
03-Jan-2004 10:55
Or google for "win32.hlp". Almost every API-function is listed in there.
Sami Fouad
13-Dec-2003 02:33
http://msdn.microsoft.com/library/ contains functions for use with this extension.

Beware! The menu system is very dense, and confusing at first if you don't know where your going.

Luckily for you I am going to add how to get there in this note. ;)

Windows Development > Development Guides > Windows API > Windows API Reference

Enjoy.
24-Aug-2003 05:42
The small, unofficial documentation is now available here http://wobster.mynnga.de/w32api.txt .
The old link from the post above is dead.

Note that the W32API doesn't seem to be under development anymore. E-Mails to the author stayed unanswered.
If you really have to use it, just some hints here: There are often problems concerning Apache webservers. This extension doesn't seem to work with mod_php.
I used the API on IIS5 with PHP as CGI. Additionally the IUSR_<hostname> (that's the user IIS runs php.exe by default) might need additional rights to be able to call certain API-functions.
silver_dragoon77 at hotmail dot com
28-Jun-2003 04:03
hi

for phpgtk users, who might want to add some sound to their apps, here is the code, assuming ding.wav is in the script's directory

$api = new win32;
$api->registerfunction("long sndPlaySound (string a, int b) From winmm.dll");
$api->sndPlaySound("ding.wav", 0);

you can use the big win32.hlp file containing the win32 api reference to get some other multimedia functions

regards
wobble at gmx dot de
01-Apr-2003 06:09
I played a bit around with the W32API. Here is some code that actually works with the current release of W32API.
The interface changed completely, so all documentation about this extension is out-dated. While the old release
just implemented "plain" functions, the current version offers a class to handle all the API-related operations.
Additionally, functions are now registered using a SQL-like language with a single string.

<?php

$api
= new win32;

/*
     BOOL GetUserName(
        LPTSTR lpBuffer,    // address of name buffer
        LPDWORD nSize       // address of size of name buffer
     );
    Returns the current thread's username
    "&" passes argument as "refrence" not as "copy"
*/
$api->registerfunction("long GetUserName (string &a, int &b) From advapi32.dll");

/*
    DWORD GetTickCount(VOID)
    Returns the ms the OS is running
*/
$api->registerfunction("long GetTickCount () From Kernel32.dll");

$len = 255;                   // set the length your variable should have
$name = str_repeat("\0", $len); // prepare an empty string
if ($api->GetUserName($name, $len) == 0)
{
    die(
"failed");
}

if (!(
$time = $api->GetTickCount()))
{
    die(
"failed");
}

echo
"Username: $name<br>\nSystemtime: $time<br>\n";

?>

GOOD LUCK !!

Jan Kleinsorge
arunasphp at anm dot org
06-Aug-2002 05:32
In order to use most (perhaps all?) of the win32 API while running with a web server you have to give the server service permission to interact with the desktop.  This is especially noticeable with the given example, where the script will try to display message boxes on the server's display.

Keep in mind, however, that you should think hard about the consequences of letting a web server interact with your desktop, especially if you're not the only one using the web server.

 
show source | credits | sitemap | contact | advertising | mirror sites