Re: Invoking a DLL with PHP

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Richard Davey escribió:

Hi Jay,

Monday, October 17, 2005, 4:15:58 PM, you wrote:

Unfortunately I may not be able to have the DLL re-built with the
COM interface. It is an older DLL containing engineering functions
and it is huge. The real dingle here is that I only need to access
some of the functionality of the DLL. I also do not want to compile
it into PHP as it (the DLL) is a moving target.

If the resources allow, you could always write a small command-line
driven Windows app that passes arguments through to the DLL functions
and returns the results? Then exec() the app. It's a bit too messy for
my liking, but it's certainly an option.

Cheers,

Rich
Hi all,

I did some succesful works on this issue using php4, i don't know if all the methods i'm going to tell you work for php5 anyway.

The details of what you need to do with that dll from the php code or the way the target dll works will let you take one or other way... These are some of them:

You can build your own dll -or use that older dll as you say-, assuming it have exported the necessary functions and calling them using the php_w32api extension, just register necessary types, functions and you're ready to go, without any kind of recompilation of php or any dll static linking, the dll is just loaded when you register the dll functions from the php code using that beautiful extension. There are some tricks if you take this way, in relation with the type and size of data you need to send or receive from the dll, but it works pretty well. And you could code your own dll wrapper interface to the older dll if some workaround is needed to have it working -perhaps callbacks, hard data types, etc.-

Anyway could be a bit hard to success if you have to send or receive complex data types like arrays, pointers, handles, etc. etc. but it really depends on what you need to do with your data in the dll side, maybe you could serialize and send as a string for the whole array -excuse me, sure this is a bit off topic for your case-, or perhaps you could call a function per every single item in the array you want to send to the dll, then when finished maybe call another function to process the previously loaded data. Calls via this extension really go very fast and cause very low overhead.

Another way is by using your dll from a COM interface as Richard says, an easy way to do this could be create an activex dll from Vb6 (that "dll" or "exe" is just a com server or maybe you want to call it "ole", but for this is just the same thing). Then, you could write the needed code in Vb for your functionality or perhaps wrapping the dll with this Vb activex object. This way you can send from php easily complex data types like arrays, and use an oo interface to the dll. Maybe you will need to hide some of the complexities with data types in the Vb COM interface instead of having to lead with this in the php code -what happens with the first way exposed-. So for some uses this can be better. The worse is that you need to register the object in the registry, as it is a COM server.

One more way is to create your library functions -or wrapper functions- within a vc++ executable, and embed php into it, this way you can code the php-dll interface as you were coding a php extension and use that functions as php functions and methods, linking your project with php_embed and handling it inside your executable to do the work. Of course, this way isn't really possible if you need to have php running on a webserver, as you need to link dynamically with php4_ts.dll

These methods give you poweful ways to extend or workaround over php limits... :-P

So that was my 2cents. :^)

Hope it helps to clears a bit what could you do to get the job done.

Gonzalo.

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux