Page 1 of 1

PHP with C++

Posted: Tue Jun 15, 2004 4:44 am
by Youness
Hello,
I am trying to use a php interface to call an executable compiled in C++.
I first succeeded in using the executable’s functions and store my results in text file.
Now I am trying to use only the memory models instead of files to manipulate my actions and results with my classes, but I don’t now how to figure out with. Any help would be welcome:

My php script is :

Code: Select all

<?
//&op, &ent1, &ent2 are my variables putted in text zone in an html page
$op = $_POST['ComponantName'];
$ent1=$_POST['Diametre'];
$ent2=$_POST['Long'];
$handle = popen('fonction','w');
$contenu = "$op $ent1 $ent2";
//Fonction utilisé pour l'ecriture du flux
fwrite($handle, $contenu);
//Fonction utilisé pour la lecture du flux
echo "L'écriture de $contenu dans le fichier a réussi <br>";
pclose($handle);
?>
The C++ Classe :

Code: Select all

class Componant  
&#123;
int Diametre;
int Long;
public:
Componant();
virtual ~Componant();
&#125;; 

The constructor: 

Componant::Componant(int D, int L)
&#123;
Diametre = D;
Long= L;
&#125;

I use a function to create an instance of my class with the desired values :
void AddComponant(char name, int D, int L)
&#123;
new Componant MyComponant = Componant(name,D,L);	
&#125;
Thinks !!!

feyd|use

Code: Select all

and

Code: Select all

tags.[/color]

Posted: Tue Jun 15, 2004 9:35 am
by John Cartwright
added php tags

Code: Select all

&lt;?php
&lt;? 
//&amp;op, &amp;ent1, &amp;ent2 are my variables putted in text zone in an html page 
$op = $_POST&#1111;'ComponantName']; 
$ent1=$_POST&#1111;'Diametre']; 
$ent2=$_POST&#1111;'Long']; 
$handle = popen('fonction','w'); 
$contenu = "$op $ent1 $ent2"; 
//Fonction utilisé pour l'ecriture du flux 
fwrite($handle, $contenu); 
//Fonction utilisé pour la lecture du flux 
echo "L'écriture de $contenu dans le fichier a réussi &lt;br&gt;"; 
pclose($handle); 
?&gt; 

The C++ Classe : 

class Componant 
{ 
int Diametre; 
int Long; 
public: 
Componant(); 
virtual ~Componant(); 
}; 

The constructor: 

Componant::Componant(int D, int L) 
{ 
Diametre = D; 
Long= L; 
} 

I use a function to create an instance of my class with the desired values : 
void AddComponant(char name, int D, int L) 
{ 
new Componant MyComponant = Componant(name,D,L); 
} 

Thinks !!! 
?&gt;

Posted: Tue Jun 15, 2004 10:11 am
by Weirdan
in your c++ program you have to read the values from stdin, something like this:

Code: Select all

char&#1111;] name;
  int d;
  int l;
  name<<stdin;
  d<<stdin;
  l<<stdin;

PHP with C++

Posted: Wed Jun 16, 2004 4:17 am
by Youness
Is it possible to create a link (API calling) between php script and a c++ code without creating a switch on the method in the c++ code ?

Posted: Thu Jun 17, 2004 12:30 am
by Weirdan
via [php_man]com[/php_man] or [php_man]w32api[/php_man] (which is completely broken in PHP4). There's also php_ffi extension mentioned in user comments on w32api manual page.