XP, PHP & C++

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Toune
Forum Newbie
Posts: 5
Joined: Fri Dec 12, 2003 1:54 am

XP, PHP & C++

Post 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.

:roll: I know how to do with perl but no with php... :!:

:idea: Do you know a method to interface the two programs : php & C++ ?

If you have samples ... :lol:

Thank's

Toune
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Post by Weirdan »

may be this will be of help....
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post 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
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Post by Weirdan »

or [php_man]W32api[/php_man] PHP functions?
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post 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
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Post 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';
User avatar
Pyrite
Forum Regular
Posts: 769
Joined: Tue Sep 23, 2003 11:07 pm
Location: The Republic of Texas
Contact:

Post 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.
User avatar
m3mn0n
PHP Evangelist
Posts: 3548
Joined: Tue Aug 13, 2002 3:35 pm
Location: Calgary, Canada

Post 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
(
    &#1111;0] =&gt; registerfunction
    &#1111;1] =&gt; unregisterfunction
    &#1111;2] =&gt; registercallback
    &#1111;3] =&gt; definetype
    &#1111;4] =&gt; gettypesize
    &#1111;5] =&gt; inittype
    &#1111;6] =&gt; decref
)
Is there supose to be more?

edit: never mind this question, i've relized how to use this ;)
Last edited by m3mn0n on Fri Dec 12, 2003 9:08 pm, edited 1 time in total.
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Post by Weirdan »

for those who is interested. I've found documentation on new win32 interface: http://wobster.mynnga.de/w32api.txt
User avatar
m3mn0n
PHP Evangelist
Posts: 3548
Joined: Tue Aug 13, 2002 3:35 pm
Location: Calgary, Canada

Post 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
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Post 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.
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

ah win32api is object-based :oops:

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
:arrow: Kernel32.dll
User avatar
m3mn0n
PHP Evangelist
Posts: 3548
Joined: Tue Aug 13, 2002 3:35 pm
Location: Calgary, Canada

Post 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)

8)
Toune
Forum Newbie
Posts: 5
Joined: Fri Dec 12, 2003 1:54 am

Post by Toune »

HI!

Thank for yours good explanations... :P

I avance in my project with your help ! 8)

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 ... :oops:

Toune
Bitmaster
Forum Newbie
Posts: 20
Joined: Thu Nov 21, 2002 8:42 am

Post 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)
Post Reply