0

In PHP 4.4.4 (bamcompiler to be more precise) I try to use w32api FFI to interface with iup GUI library like this:

<?
$iup=new win32;
$iup->registerfunction("int IupOpen (int argc,string argv) From iup.dll");
$iup->registerfunction("int IupClose () From iup.dll");
$iup->registerfunction("int IupMainLoop () From iup.dll");
$iup->registerfunction("long IupDialog (long child) From iup.dll");
$iup->registerfunction("int IupShow (long child) From iup.dll");
$iup->registerfunction("long IupHboxv (long &child) From iup.dll");
$iup->registerfunction("long IupLabel (string title) From iup.dll");
$iup->registerfunction("long IupButton (string title,string action) From iup.dll");
$iup->registerfunction("long IupSetAttributes (long ih,string attrs) From iup.dll");
$iup->IupOpen(null,null);
$b=$iup->IupButton("vasile","apasa");
$l=$iup->IupLabel("asta e vasile");
$hbc=pack("L*x",$l,$b);
$hb=$iup->IupHboxv(&$hbc);
$dia=$iup->IupDialog($hb);
$iup->IupSetAttributes($dia,"SIZE=300x200");
$iup->IupShow($dia);
$iup->IupMainLoop();
$iup->IupClose();
?>

and all I get is an empty window.

If I give the address of one of the controls to IupHboxv ex:(&$b), I get that control in the window, so I think it have something to do with the address of the packed string.

The w32api is too thin and for the pack function I've read the Perl docs.

halfer
  • 19,824
  • 17
  • 99
  • 186
tbmale
  • 185
  • 1
  • 1
  • 5
  • I come up with an ugly hack: `function Hbox(){ global $iup; $argv=func_get_args (); $narg=implode(",", array_fill(0, count($argv), "long child")); $iup->registerfunction("long IupHbox ($narg) From iup.dll"); $eval="return \$iup->IupHbox(".implode(",",$argv).");"; $res=eval($eval); echo($iup->unregisterfunction("IupHbox")); return $res; } ` but, although returns true, unregisterfunction doesn't really work, as I get an error second time I want to use registerfunction. So... I keep digging :) – tbmale Jul 28 '13 at 14:03
  • This is a less ugly hack, that's fortunately working: `$iup->registerfunction("long IupHbox (long child,long child) From iup.dll"); ;function Hbox($argv){ echo(count($argv)."\n"); global $iup; // $argv=func_get_args (); $v1=array_pop($argv); $v2=array_pop($argv); $val=is_null($v2)?$iup->IupHbox($v1,$v2):$iup->IupHbox($v2,$v1); if(count($argv)>0){$argv[]=$val;return Hbox($argv);} else return $val; };$hb=Hbox(array($c1,$c2,$c3,...)); `. It's not really answering the question **how to get pass a C vector to a foreign function**, so it is still open, this is just a workaround. – tbmale Jul 28 '13 at 16:42

0 Answers0