如何从 PHP 调用 winapi 函数? [英] How to call winapi functions from PHP?

查看:26
本文介绍了如何从 PHP 调用 winapi 函数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

1) 如何从 PHP 调用 winapi 函数?
2) 如何加载任何dll文件并从中调用函数?

平台:ms windows, php5

php_w32api 扩展不可用.

也许有使用 COM 对象的解决方案?

解决方案

你提到了 stats.试试...

<前>$wmi_call = "wmic process where \"name like '%php%'\" list statistics";系统($wmi_call,$output);var_dump($output);

我对 win api 替代方案的回答可能令人沮丧,但在这里......

Winbinder,除了提供创建 GUI 的功能外,它还具有加载和使用 dll 的功能.您必须检查他们的论坛,以获取指向最新的准系统、单个 dll 扩展文件的链接,而不是实施他们的整个过时的 PHP 包.请注意 - 他们的网站最近没有更新,存在一些错误和稳定性问题,函数名称有时与其文档不同.

COM() 会让你更接近,但仍然没有远远不够.请参阅这篇 tuxradar.com 文章,了解如何使用 PHP/COM.尽管如此,除了一些典型的 com 接口(如 vbscript 主机、MS 办公应用程序等)之外,PHP 无法处理其他很多事情.

DOTNET() 会让您走得更远.请参阅有关该主题的这篇 peachpit.com 文章.不完全是我所说的挂钩到 win api,但这将允许您使用数百个"更多 .net 类和方法.有关 .net 附带的标准类库的文档,请参阅 msdn框架.请注意,PHP 的 DOTNET 依赖于 COM,除非库作者在他们的库中明确启用 com 功能(大多数都没有),否则您无法使用它.此外,这个 DOTNET 类似乎非常有限且不成熟.与 VB 在导入和使用 .net 和 com 库方面的实际拖放功能相比,PHP 实际上是残缺的,因此您将花费大量时间设计草率的解决方法.例如,在 PHP 中创建交互式窗体时,您不能像您期望的那样执行 $form_object->Controls->Add($button_object),但您可以执行 $button_object->Parent = $form_object.

我个人尝试过使用 COM() 和 DOTNET() 实现几个 com 和 .net 库,但只有少数工作......几乎没有.恕我直言,我建议您构建、编译和注册为 .net 程序集,或者编写您自己的支持 com 的简短 VB 类,您可以使用 DOTNET() 或 COM() 从 PHP 脚本中连接到该类.PHP 手册页和上面链接的 peachpit.com 文章将进行解释.VB 可以动态导入其他 dll 并将它们的类和方法公开给您的 PHP 脚本.搜索直接来自 PHP 的方法可能比构建这个简短的解决方案需要更长的时间.

1) How to call winapi functions from PHP?
2) How to load any dll file and call functions from it?

Platform: ms windows, php5

php_w32api extension is not avalaible.

Maybe there is solution using COM objects?

解决方案

You mentioned stats. try...


$wmi_call = "wmic process where \"name like '%php%'\" list statistics";
system($wmi_call, $output);
var_dump($output);

My answer for alternatives to win api may be disheartening, but here it goes...

Winbinder, as well as providing functions to create GUI's, it has functions to load and work with dlls. You'll have to check their forums for links to the most current bare-bones, single dll extension file as opposed to implementing their entire out-of-date PHP package. Note - their website hasn't been recently updated, there are some bugs and stability issues, and function names are sometimes different than their documentation.

COM() will get you closer, but still not far enough. See this tuxradar.com article on working with PHP/COM. Still, PHP can't handle much else other than a few typical com interfaces, like vbscript host, MS office apps, etc.

DOTNET() will get you even further. See this peachpit.com article on the topic. Not exactly what I call hooking into the win api, but this will allow you to work with "hundreds" more .net classes and methods. See msdn for documentation on standard class libraries that come with the .net framework. Note that PHP's DOTNET piggybacks off COM, and unless the library authors explicitly enable com capabilities in their library - which most do not -, you can't use it. Also, this DOTNET class seems very limited and not mature. Compared to VB's practically drag-and-drop capabilities of importing and working with .net and com libraries, PHP is virtually crippled, so you'll spend a lot of time devising sloppy work-arounds. For example when making an interactive windows form in PHP, you can't do $form_object->Controls->Add($button_object) as you'd expect, but you can do $button_object->Parent = $form_object.

I've personally tried implementing several com and .net libraries using COM() and DOTNET(), and only a handful worked... barely. IMHO, I'd recommend building, compiling, and registering as a .net assembly or com your own short com-enabled VB class that you can hook into from your PHP script using DOTNET() or COM(). The PHP manual pages and the the peachpit.com article linked above will explain. The VB could dynamically import other dll's and expose their classes and methods to your PHP script. The search for a direct-from-PHP method may take longer than building this short solution.

这篇关于如何从 PHP 调用 winapi 函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆