Invoking a DLL with PHP
Good morning gurus and gurettes!
I have been asked (and I think that we may have discussed this before in
general terms, a long time ago) to perform the preliminary analysis on a
project that ideally would have me invoking an existing .DLL using PHP. I
have been googling for tidbits for several days without much luck. I have
not built a test, but I will be doing so later today or tomorrow.
Does anyone have any insight to this type of process? Would I have to build
a PHP extension and compile the DLL as part of PHP's configuration? Ideally
the DLL would be a black box that could be accessed utilizing functions that
I build without a re-compile of any type.
Thanks for any insight that you may have...all clues welcome!
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Re: Invoking a DLL with PHP
Hi Jay,
Monday, October 17, 2005, 3:20:58 PM, you wrote:
> Does anyone have any insight to this type of process? Would I have
> to build a PHP extension and compile the DLL as part of PHP's
> configuration? Ideally the DLL would be a black box that could be
> accessed utilizing functions that I build without a re-compile of
> any type.
Have only done this once, but I didn't compile the DLL into PHP
because that would have meant updating the php build every time a new
DLL was released, and updating the functions / documentation
accordingly.
The DLL was built specifically with a COM interface which I accessed
using the PHP COM functions (as I'm sure you've seen already). The DLL
authors had to rejig their original code a little, but it was a far
less painful process than compiling the DLL into PHP. However for the
next revision we are likely to move the DLL code into the .NET
framework, build a SOAP interface to it (C#) and let PHP talk to it
that way. Although that's more of a political decision than a
technical one, I'm just mentioning it incase the idea is useful for
you.
Cheers,
Rich
--
Zend Certified Engineer
http://www.launchcode.co.uk
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
RE: Invoking a DLL with PHP
[snip]
The DLL was built specifically with a COM interface which I accessed using
the PHP COM functions (as I'm sure you've seen already). The DLL authors had
to rejig their original code a little, but it was a far
less painful process than compiling the DLL into PHP. However for the next
revision we are likely to move the DLL code into the .NET framework, build a
SOAP interface to it (C#) and let PHP talk to it that way. Although that's
more of a political decision than a technical one, I'm just mentioning it
incase the idea is useful for you.
[/snip]
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. This may be one of those projects where I say,
"Give me some more development folks and we'll get it done right." otherwise
we may not be able to do the project as it exists.
I am researching the requirements for adding the COM interface now.
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Re[2]: Invoking a DLL with PHP
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
--
Zend Certified Engineer
http://www.launchcode.co.uk
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Re: Invoking a DLL with PHP
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
RE: Invoking a DLL with PHP
[snip]
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.-
[/snip]
php_w32api extension...that sounds like a plan....I wonder why it is not
mentioned with regards to things like this?
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
RE: Invoking a DLL with PHP
[snip]
[snip]
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.-
[/snip]
php_w32api extension...that sounds like a plan....I wonder why it is not
mentioned with regards to things like this?
[/snip]
I also forgot to ask if you would expand on your methodology a little,
perhaps with an example?
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php