如何从 Windows 上的 php 的 dll 调用函数?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1955429/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 13:38:12  来源:igfitidea点击:

How do I call a function from a dll from php on windows?

phpwindowsdllfunctioncall

提问by marc40000

I'm using xampp.

我正在使用 xampp。

I search and it looks like for php 4.x, there was an extension called php_w32api.dll which seems to have vanished for php 5.x. Nevertheless, it's still in the documentation on php.net but marked as experimental.

我搜索,它看起来像 php 4.x,有一个名为 php_w32api.dll 的扩展名,它似乎在 php 5.x 中消失了。尽管如此,它仍然在 php.net 的文档中,但被标记为实验性的。

Some suggested to use win32std in pecl instead, but that just wraps some function of the win32 api, but doesn't allow me do call my own dll functions. :/

有些人建议在 pecl 中使用 win32std,但这只是包装了 win32 api 的一些功能,但不允许我调用自己的 dll 函数。:/

There is ffi, but the link on the pecl site is dead and it seems like development has stopped in 2004.

有 ffi,但 pecl 站点上的链接已失效,而且开发似乎在 2004 年停止了。

Any idea how to do this without writing my own php extension?

知道如何在不编写自己的 php 扩展的情况下做到这一点吗?

Best regards Marc

最好的问候马克

回答by streetparade

COM functions are only available for the Windows version of PHP. .Net support requires PHP 5 and the .Net runtime. No installation needed to use these functions; they are part of the PHP core.

COM 函数仅适用于 Windows 版本的 PHP。.Net 支持需要 PHP 5 和 .Net 运行时。无需安装即可使用这些功能;它们是 PHP 核心的一部分。

First create your ActiveX dll (Visual Basic): Name your project as "foo" and class as "bar".

首先创建您的 ActiveX dll (Visual Basic):将您的项目命名为“foo”,将类命名为“bar”。

'---start VB code---
Public Function hello() As String
   hello = "Hello World!"
End Function
'---end VB code---

Then make the dll and register it with regsvr32.exe Now create your PHP script:

然后制作 dll 并使用 regsvr32.exe 注册它 现在创建你的 PHP 脚本:

 <?php
    $obj = new COM("foo.bar");
    $output=$obj->hello(); // Call the "hello()" method
    // once we created the COM object this can be used like any other php classes.
    echo $output; // Displays Hello World! (so this comes from the dll!)
    ?>