将 DLL 与 PHP 结合使用(傻瓜式教程)
我有一个项目需要使用 PHP 访问 DLL。服务器是Windows机器,Apache服务器由XAMPP提供。
我在网上阅读了多个答案,例如
- Use DLL in PHP?
- php 与 dll 通信?
- 通过php调用dll
- http://ca.php.net/manual/en/class.com.php
- https://www.php.net/manual/en/book.w32api.php< /a>
- http://www.talkphp.com/absolute-beginners/3340-php-how-load-com-dll-file.html
这是我在 HTA /
Javascript
:
有人有工作示例吗?
这是我迄今为止在 PHP 中尝试的内容:
$obj = new COM('pathTo.dll');
有关 DLL 的信息:
- 已编译使用Delphi
- (当然)是自制的,
- 当我尝试使用
regsvr32
注册DLL时,出现以下错误找不到DllRegister服务器入口点
它可以使用吗无需注册与 regsvr32 一起使用吗?
I have a project that needs to access a DLL with PHP. The server is a Windows machine and the Apache server is provided by XAMPP.
I read multiple answers on the web like
- Use DLL in PHP?
- php communication with dll?
- calling dll through php
- http://ca.php.net/manual/en/class.com.php
- https://www.php.net/manual/en/book.w32api.php
- http://www.talkphp.com/absolute-beginners/3340-php-how-load-com-dll-file.html
Here is how I call the DLL in HTA
/ Javascript
:
<object style="display:none" id="SOME_ID" classid="clsid:SOME_CLASS_ID" codebase="./somePath.dll"></object>
Does someone have a working example?
Here is what I tried so far in PHP:
$obj = new COM('pathTo.dll');
Information on the DLL:
- Compiled using Delphi
- It is (of course) home made
- I get the following error
the DllRegister Server entry point was not found
when I try to register the DLL withregsvr32
Can it be used without registering it with regsvr32
?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
创建 DLL 文件时,需要使用 模块定义文件。它将包含与此类似的内容:
该定义允许 regsvr32 查找 DllRegisterServer 入口点。
您可以尝试的另一个选项是将 /n 标志传递给 regsvr32。
最终,在尝试使 DLL 与 PHP 一起工作之前,您需要确保 DLL 能够正常工作。
When you create your DLL file, you need to use a module definition file. It will contain something similar to this:
That definition allows regsvr32 to find the DllRegisterServer entry point.
Another option you can try is to pass the /n flag to regsvr32.
Ultimately, before you try to make a DLL work with PHP, you need to be sure your DLL works in general.
随着 PHP>=7.4.0 的新 FFI/Foreign Function Interface (当这个问题发布时,它还不存在),现在比以前更容易了!例如,调用 GetCurrentProcessId(); kernel32.dll 中的 函数:
输出
:)
With PHP>=7.4.0's new FFI/Foreign Function Interface (which didn't exist yet when this question was posted), this is now easier than ever before! For example, to call the GetCurrentProcessId(); function from kernel32.dll:
outputs
:)
我遇到了同样的问题,我修复了一些步骤:
在 DLL 文件所在的路径中写入:
C:\Windows\system32\regsvr32 xwizards.dll
(示例)出现一个窗口,显示“DLLRegisterServer success”
现在写入您的 PHP 代码:
<前><代码>尝试{.'); //NameOfDllFile 不带扩展名“.dll”
$dll = new COM('
$dll->函数();
} catch(异常$e){
回显'错误:'。 $e->getMessage(), "\n";}
现在,如果您知道如何管理 dll 的类和函数,那就没问题了,但是屏幕上不应该显示任何错误消息
如果我不清楚,请告诉我,下次我会尽力而为: )
I had the same problem and i fixed some steps :
write the PATH where you're your dll file:
C:\Windows\system32\regsvr32 xwizards.dll
(it's example)a window show up with "DLLRegisterServer success"
now write into your PHP code :
Now if you know how manage the class and the function of you're dll it's going ok,however no error massage should show up on your screen
If i wasn't clear let me know and i'll do my best the next time :)
无法从 Linux/Apache 服务器访问 DLL。因此该项目被放弃。
A DLL cannot be access from Linux/Apache server. Therefore the project was drop.