tags:

views:

227

answers:

3

We are interfacing with a piece of hardware developed here, and allowing access via the web. The firmware for this device is written in C, and part of that firmware is about 5000 lines of code that parses huge binary files for config data, compiled to a .dll.

Is there any way under heaven that I can access a .dll, written in C, from PHP?

I'm betting it's a no, but before starting a quest to duplicate 5000 lines of C in PHP, I thought I'd give the experts here a shot.

Thanks all.

JH

+1  A: 

Couldn't you just compile the parts of the DLL you need into an executable file, and execute it from php and utilize the results?

Something like

$data = `someprogram --options`

Then just use the data however you want.

Alex Fort
+6  A: 

yes, you can use it as a php extension (which are written in C), but you might need some modifications .. etc

http://devzone.zend.com/node/view/id/1021

I think this question is related to yours.

Aziz
+1  A: 

You might want to check out SWIG, a general tool for wrapping libraries so that they may be called from a variety of languages. PHP is supported by SWIG, as are Perl and Lua (the targets I've personally used). Quoting from the features list at the SWIG website:

SWIG currently generates wrapper code for eighteen different target languages:

  • Allegro CL
  • C#
  • CFFI
  • CLISP
  • Chicken
  • Guile
  • Java
  • Lua
  • Modula-3
  • Mzscheme
  • OCAML
  • Octave
  • Perl
  • PHP
  • Python
  • R
  • Ruby
  • Tcl
  • UFFI

In addition to this, the parse tree can be exported as XML and Lisp s-expressions. Experimental work is also available for a Pike module.

Some of its features are dependent on back-end support in the per-language wrapper generators, but in general it provides easy to use wrappers for passing all plain-data value types in and out of functions. Where the target language has the concept, it can usually map object models as well.

RBerteig