What's the best method to load a dll in php?

I'm developing a web app using CakePHP on the server side, and I need to use a dll provided by a 3rd party to access their platform, so I don't have the source code of the dll and I can't modify it. I've searched about this and I haven't found a simple way to do this.

What is the best way to load a dll in php?

Should I build an php extension that acts as a wrapper to the 3rd party dll?

It's there other method available?

Thanks in advance.

UPDATE

I've found that I can use the dll as a COM object but I would need to register the dll on Windows every time the client needs to deploy the server, and I would like a solution that does not involve registering the dll.

UPDATE

I tried registering the dll, but i got an error ("the entry-point DllRegisterServer was not found"), which means it probably is not compiled to be used as a COM object. I think the only options are to create a C/C++ php extension that wraps the dll or create a C++/C# COM object that wraps the dll and use it using the DOTNET php extension.

Upvotes: 3

Views: 3257

Answers (1)

I ended up implementing a .NET COM visible Wrapper for the dll, I imported the dlls functions like this:

[DllImport("dapi.dll", EntryPoint = "#100", PreserveSig = false,
         CallingConvention = CallingConvention.StdCall)]
    public static extern Idapi CreateDapi();

I registered the Wrapper as a COM object using the regasm.exe utility in cmd:

regasm /codebase dapiWrapper.dll

And in php I instanciated the COM Object like this:

$this->dapiCom = new COM("DapiWrapper.DapiWrapper") or die("Error");

Upvotes: 2

Related Questions