Page 1 of 2
XP, PHP & C++
Posted: Fri Dec 12, 2003 5:04 am
by Toune
Hi,

I wrote in MS Visual C 6.0 a procedure with input and output parameters, and I want to use it in a php program in windows xp.

I know how to do with perl but no with php...

Do you know a method to interface the two programs : php & C++ ?
If you have samples ...
Thank's
Toune
Posted: Fri Dec 12, 2003 9:08 am
by Weirdan
may be
this will be of help....
Posted: Fri Dec 12, 2003 10:09 am
by volka
the link gives you an overview of how to write a plugin for php.
Of course you can write one but maybe you're content with something simpler
http://php.net/exec - calling another program and fetching its output
Posted: Fri Dec 12, 2003 10:10 am
by Weirdan
or [php_man]W32api[/php_man] PHP functions?
Posted: Fri Dec 12, 2003 10:17 am
by volka
has apparently been discontinued.
Code: Select all
<?php
if (extension_loaded('Win32 API'))
print_r(get_extension_funcs ('Win32 API'));
else
echo 'extension not loaded';
?>
gives me
Array
(
)
on my win32/php 4.3.4 system
Posted: Fri Dec 12, 2003 12:05 pm
by Weirdan
there is information in user comments in php manual:
wobble at dmx dot de wrote:
I played a bit around with the W32API. Here is some code that actually works with the current release of W32API.
The interface changed completely, so all documentation about this extension is out-dated. While the old release
just implemented "plain" functions, the current version offers a class to handle all the API-related operations.
Additionally, functions are now registered using a SQL-like language with a single string.
try
Code: Select all
if (extension_loaded('Win32 API')){
$api = new win32;
print_r(get_class_methods($api));
} else echo 'extension not loaded';
Posted: Fri Dec 12, 2003 3:38 pm
by Pyrite
There is also phpGtk, allowing to write GUI programs using the GTK UI. And now that GTK2 is ported to Windows, and quite a few Linux apps are ported to windows because of it, I imagine you could do the same and write a visual gui program for windows XP in php.
Posted: Fri Dec 12, 2003 4:38 pm
by m3mn0n
download it here:
http://kromann.info/php4.php
I didnt get it with my windows version of php either.
btw:
Code: Select all
<?php
if (extension_loaded('Win32 API'))
{
$api = new win32;
echo '<pre>';
print_r(get_class_methods($api));
echo '</pre>';
} else {
echo 'extension not loaded';
}
?>
gives me:
Code: Select all
Array
(
ї0] => registerfunction
ї1] => unregisterfunction
ї2] => registercallback
ї3] => definetype
ї4] => gettypesize
ї5] => inittype
ї6] => decref
)
Is there supose to be more?
edit: never mind this question, i've relized how to use this 
Posted: Fri Dec 12, 2003 5:39 pm
by Weirdan
for those who is interested. I've found documentation on new win32 interface:
http://wobster.mynnga.de/w32api.txt
Posted: Fri Dec 12, 2003 6:34 pm
by m3mn0n
That is nice, but what I really want is a list of things that I can do with this thing. I can't find one anywhere.
How do you know which .dll does what? And which functions to use for each dll?
Such as:
long GetTickCount () From Kernel32.dll
long GetUserName (string &a, int &b) From advapi32.dll
& long sndPlaySound (string a, int b) From winmm.dll
Posted: Fri Dec 12, 2003 7:01 pm
by Weirdan
I do use
http://www.webwareindex.com/Download/win32api.zip. It's VB declarations of the win32 api function and it contains dll names for each function. If you need to know what each function is intended for, get some book on win32 api. Or use
http://msdn.microsoft.com
Also I got nice utility, called
PE explorer. It's useful if you wish to know what functions the given .dll exports.
Posted: Fri Dec 12, 2003 7:26 pm
by volka
ah win32api is object-based
http://msdn.microsoft.com/library/default.asp knows which dll implements which function
e.g.
GetTickCount
The GetTickCount function retrieves the number of milliseconds that have elapsed since the system was started.
[...]
Server: Included in Windows Server 2003, Windows 2000 Server, and Windows NT Server.
Header: Declared in Winbase.h; include Windows.h.
Library: Use Kernel32.lib

Kernel32.dll
Posted: Fri Dec 12, 2003 7:41 pm
by m3mn0n
Very cool! Thanks guys.
I just want to note that menu system is very dense, and confusing at first if you don't know where your going. Plus my inquery wasn't in the search results so that made me frustrated for a bit, heh. After some exploring I found the reference page....
Windows Development >
Development Guides >
Windows API >
Windows API Reference
Functions in alphabetical order
Functions by catagory
(more sorting on the left menu)

Posted: Mon Dec 15, 2003 2:26 am
by Toune
HI!
Thank for yours good explanations...
I avance in my project with your help !
But I am blocked on messagebox procédure :
<?php
error_reporting(E_ALL);
define("MB_OK", 0);
$api = new win32();
$api->registerfunction("int MessageBoxA (long hWnd,
string &title,
string &lpCaption,
int uType )
From user32.dll");
$titre="My Title";
$msg="My Message";
$hnd=NULL;
$a=$api->MessageBoxA($hnd,$titre,$msg,MB_OK);
print ("Answer: $a\n");
$a=$api->unregisterFunction("MessageBoxA");
print ("Answer: $a\n");
?>
The message box don't show. and the answer is 0 !
I make a mistake but I don't know where ...
Toune
Posted: Mon Dec 15, 2003 6:51 am
by Bitmaster
If you run the application from a web server (Apache, IIS etc), no message box will appear, since the Web Server runs as a system service and doens't have the right to interact with the desktop. The service runs even if no user is logged on, so there's no desktop.
If you call a function that interacts with the desktop (like MessageBox), it will only work if you launch PHP as a command line tool (PHP CLI)