18

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

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:

  1. Compiled using Delphi
  2. It is (of course) home made
  3. I get the following error the DllRegister Server entry point was not found when I try to register the DLL with regsvr32

Can it be used without registering it with regsvr32?

Community
  • 1
  • 1
David Laberge
  • 13,061
  • 14
  • 51
  • 82
  • What's the CLSID of your COM class? I suspect you're not creating a DLL that's ready for COM interop... – Thorsten Dittmar Dec 21 '11 at 13:38
  • Everything I have ever read on this subject tells me that the way to do this is to write a C++ wrapper for the DLL that can be built into a PHP extension, and use it that way. I have never tried to do it and can't tell you how, but I have come across the question before (you linked to a couple of people asking the same question) and I have never seen anyone say "I got it to work" unless they built an extension. – DaveRandom Dec 21 '11 at 13:41
  • @ThorstenDittmar `CLSID` is a string AlphaNumeric string with the following format XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX. What do you mean by a DLL ready for COM interop – David Laberge Dec 21 '11 at 13:41
  • @DavidLaberge `CLSID` is (I think) technically a [UUID](http://en.wikipedia.org/wiki/Universally_unique_identifier), and may need to be wrapped in `{}` when used in this context – DaveRandom Dec 21 '11 at 13:42
  • Well, from what I've seen in the links and your question, you must register your DLL with the system and register a COM class you can then use from PHP. If you're not doing that, it won't work. – Thorsten Dittmar Dec 21 '11 at 14:11
  • The fact that you get a `the DllRegister Server entry point was not found` error means something is wrong with your DLL. Make sure you defined entry points and export tables correctly. Don't go further until you have fixed that error. – Hossein Jan 11 '12 at 18:34
  • @Hossein Thanks, but can it be used without registering it with regserv32 ? – David Laberge Jan 11 '12 at 18:43
  • If using the `clsid` is the only way your code recognizes the DLL, then you must do it. For [PHP's COM](http://us.php.net/COM) also it has to be registered. Verify you have implemented the DllRegister and EXPORTed that. You should tell what you've tried so far (DLL and PHP source code). – Hossein Jan 11 '12 at 18:50

3 Answers3

15

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

;
;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.

Another option you can try is to pass the /n flag to 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)

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

Community
  • 1
  • 1
Jeremy Harris
  • 23,007
  • 13
  • 73
  • 124
0

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_dotnet extension
  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


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

Bitterblue
  • 9,526
  • 12
  • 71
  • 114
  • Could you give more details and maybe a working example? I'm at the point where it doesn't say "couldn't open file" anymore. Now it just says "class not registered". So I'm closer to the solution here. I'm working with .NET dlls. – Bitterblue Jul 26 '18 at 06:43
0

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

David Laberge
  • 13,061
  • 14
  • 51
  • 82