将 DLL 与 PHP 一起用于傻瓜

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/8590637/
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-08-26 05:02:47  来源:igfitidea点击:

Using a DLL With PHP for Dummies

phpdllxamppocx

提问by David Laberge

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.

我有一个需要使用 PHP 访问 DLL 的项目。服务器是一台 Windows 机器,Apache 服务器由 XAMPP 提供。

I read multiple answers on the web like

我在网上阅读了多个答案,例如

Here is how I call the DLL in HTA/ Javascript:

这是我在HTA/ 中调用 DLL 的方式Javascript

<object style="display:none" id="SOME_ID" classid="clsid:SOME_CLASS_ID" codebase="./somePath.dll"></object>

<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:

这是我迄今为止在 PHP 中尝试过的:

$obj = new COM('pathTo.dll');

Information on the DLL:

DLL的相关资料:

  1. Compiled using Delphi
  2. It is (of course) home made
  3. I get the following error the DllRegister Server entry point was not foundwhen I try to register the DLL with regsvr32
  1. 使用 Delphi 编译
  2. 它(当然)是自制的
  3. the DllRegister Server entry point was not found当我尝试注册 DLL 时出现以下错误regsvr32

Can it be used without registering it with regsvr32?

不注册就可以使用regsvr32吗?

采纳答案by Jeremy Harris

When you create your DLL file, you need to use a module definition file. It will contain something similar to this:

创建 DLL 文件时,需要使用模块定义文件. 它将包含与此类似的内容:

;
;contains the list of functions that are being exported from this DLL
;

DESCRIPTION     "Simple COM object"

EXPORTS
                DllGetClassObject       PRIVATE
                DllCanUnloadNow         PRIVATE
                DllRegisterServer       PRIVATE
                DllUnregisterServer     PRIVATE

That definition allows regsvr32 to find the DllRegisterServer entry point.

该定义允许 regsvr32 找到 DllRegisterServer 入口点。

Another option you can try is to pass the /n flag to regsvr32.

您可以尝试的另一个选项是将 /n 标志传递给 regsvr32。

Regsvr32 [/u] [/n] [/i[:cmdline]] dllname

/u - Unregister server

/i - Call DllInstall passing it an optional [cmdline]; when used with /u calls dll uninstall

/n - do not call DllRegisterServer; this option must be used with /i

/s – Silent; display no message boxes (added with Windows XP and Windows Vista)

Regsvr32 [/u] [/n] [/i[:cmdline]] dllname

/u - 注销服务器

/i - 调用 DllInstall 并传递一个可选的 [cmdline];与 /u 一起使用时调用 dll 卸载

/n - 不调用 DllRegisterServer;此选项必须与 /i 一起使用

/s – 静音;不显示消息框(随 Windows XP 和 Windows Vista 添加)

Ultimately, before you try to make a DLL work with PHP, you need to be sure your DLL works in general.

最后,在您尝试使 DLL 与 PHP 一起工作之前,您需要确保您的 DLL 能够正常工作。

回答by David Laberge

A DLL cannot be access from Linux/Apache server. Therefore the project was drop.

无法从 Linux/Apache 服务器访问 DLL。因此该项目被放弃。

回答by UserHelpNeeding02356

I had the same problem and i fixed some steps :

我遇到了同样的问题,我修复了一些步骤:

  1. open the command line in administrator right (windows + r + type 'cmd') 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"
  2. check your phpinfo() if you're com_dotnetextension
  3. now write into your PHP code :

        try    {
      $dll = new COM('<theNameOfDllFile>.<NameOfTheClass>'); //without extension '.dll' for theNameOfDllFile
      $dll->Function(); 
      } catch(Exception $e){
        echo 'error: ' . $e->getMessage(), "\n";}
    

    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


  1. 以管理员权限打开命令行(windows + r + 键入“cmd”)在你的 dll 文件所在的路径中写入:(
    C:\Windows\system32\regsvr32 xwizards.dll示例)
    一个窗口显示“DLLRegisterServer 成功”
  2. 如果您是com_dotnet扩展名,请检查您的 phpinfo()
  3. 现在写入您的 PHP 代码:

        try    {
      $dll = new COM('<theNameOfDllFile>.<NameOfTheClass>'); //without extension '.dll' for theNameOfDllFile
      $dll->Function(); 
      } catch(Exception $e){
        echo 'error: ' . $e->getMessage(), "\n";}
    

    现在,如果您知道如何管理类和 dll 的功能,那就没问题了,但是屏幕上不应显示错误消息


If i wasn't clear let me know and i'll do my best the next time :)

如果我不清楚,请告诉我,下次我会尽力的 :)