krakjoe August 11th, 2007, 04:19 Oh yeah, here we go ....
I'll assume already that you know php, and are confident that you can follow instructions and function prototypes similar to those you see @ php.net, that's pretty much all you need.
Firstly, a little bit about how this is done, so it doesn't seem like voodoo or something to you.
As you know php is an extendible language, you can pretty much write any C code you want to ( c++ if you're good enough ) and have php execute it, and I'm sure youre aware of PHP-GTK, well for some time now there has existed a library going by the name of WinBinder (http://winbinder.org), what winbinder does is fuses the power and glory of php with the accessibility of windows and it's own native API to allow even novice php programmers to build fully featured windows applications using thier existing knowledge and skills.
I won't go into how the Windows API works, I don't need to you don't need to know.
Here is some pseudo code with the structure of a WinBound application
<?php
// first include the wb functions that are contained in some php scripts distributed with winbinders installation package
include('winbinder.php');
// next you need to create a window probably for the user to interact with
$mainwin = wb_create_window( [ function args ] );
// next you need to draw controls on the above window
wb_create_control( $mainwin, [ function args ] );
// next you need to set a handler for that window, this function will handle the button pushes and tab changes etc in your application, it's the "brains" of the operation so to speak
wb_set_handler( $mainwin, 'process_my_window' );
// next we need to define the function and all it's procedures, notice this function has at least two parameters, the window it's for, and the id of the control being clicked, id's are specified in wb_create_control and normally defined before that, passing them works and trying to be as simple as I can be.
function process_my_window( $window, $id )
{
switch( $id )
{
// this ID is predefined by wb, it's for the exit button, and you MUST put one in
case IDCLOSE:
wb_destroy_window( $window );
break;
case IDC_BUTTON:
// your other cases and buttons and what not here
break;
}
}
// the next step is to tell wb to start looping infinitely with
wb_main_loop( );
?>
Writing windows applications from php really is as simple as that, please take a look at winbinder and it's documentation, and any questions you might have regarding it's usage feel free to ask if you don't get a response from the forums @ winbinder.
Once your applications are written, you'll notice they are still .php(w) scripts, however there are remedies for that, one of them exists : phpCompile (http://krakjoe.com/projects/phpCompile) : and of course has my name on it, so is far superior to anything else you might find, and now your php is an actual windows .exe that you can distribute like the big boys do .....
phpCompile is also suitable for making console applications from php, no further knowledge needed there, you write php scripts to do whatever you need and can turn them into an .exe to do whatever you need anywhere there is windows
Obviously the code for an actual windows application will be more complicated, but I promise not by much, and if you have the ability to use http://winasm.net winasm studio, you'll save yourself even more time, once winbinder is installed look in the examples directory for a look at most of the features that wb has to offer, this is definately one library every php programmer should know by heart ......
Thanks for listening ....
Yun August 11th, 2007, 04:49 What the...? Nice!
Seriously d'oh...what made you find this out? :S
krakjoe August 11th, 2007, 05:27 Just over a year ago, I wrote the code that drives
http://krakjoe.com/projects/myCpanelBackup
When I was finished, I wrote a form for it but it looked rubbish - and was almost useless as an application, I had heard of py2exe and started to look into writing a php2exe program, I started but didn't get very far due to the lack of support ( or so I thought ) for the windows api, so then I started to attempt to write my own php extension that gave the access I needed to put files inside and retrieve them from an exe .... I was searching a build error on google and it came up in the winbinder forum, honestly I thought it was a joke when I saw the applications that were built with it, I was certain somewhere I'd need at least some c - but no, you don't, I scrapped both my php2exe program and my winapi extension and immediately started to suck in all the information I could, I have now written two successful php2exe programs for both php4 and php5 and know winbinder pretty well .... I more or less scrapped using all code but php, I use c for hacking php for my phpCompile-Beta program but apart from that I never have to look at another dll error again, not even once ....
God I love php, I actually get butterflies in my stomach when I think about the possibilities .....
Jackel.ca August 11th, 2007, 10:45 Interesting.
If I can find some time this weekend, I'll boot into windows and give it go. Thanks Joe :)
krakjoe August 12th, 2007, 13:47 Lots of people have read the thread and no one is saying anything, is it because you don't believe me or something ??
I don't get it ... talk damn it ...
webadpro August 14th, 2007, 06:49 Wow.. nice I came up and being able to get something out.. and geez, I've got to say... WOW... this is amazing... Now I just need to learn it more and create nice looking apps.
Thanks Joe!
Joe, once we use phpCompile to compile our files, do we need to include any other files else to get the exe to execute and work as wanted? Also, would you mind explaining how to use a DB with winBinder?
Regards
krakjoe September 6th, 2007, 06:09 You can use normal mysql, or one of the flat file database drivers available for php, any php code will work, just interact as you normally would, but take special care when creating permissions for your mysql users ...
I said I would make a working example, and this morning I have, in the following archive is the following application, it's actually very simple, my coding standards might have lapsed on this because I'm very tired and just trying to wear myself out so I can sleep properly ( if you find mistakes then post ), but demonstrates well how to use wb and other extensions ....
http://img366.imageshack.us/img366/3238/utubeyw4.jpg
Like I said, entirely PHP .... heres the sources ...
http://krakjoe.com/temp/uTube.zip
raversworld September 6th, 2007, 11:28 So what is it a complete exe off of windows written in php? im sorry but i do not get it
krakjoe September 6th, 2007, 11:31 http://krakjoe.com/projects/phpCompile - yay, I wrote that one ( php4 only ) ...
http://krakjoe.com/projects/phpCompile-Beta - yay, I wrote that one too ( php5 only, most php4 scripts will work anyway, but you have a better OO interface in php5 ) ...
http://winbinder.org -- yay someone else wrote that one
WinBinder is a php extension that allows php to make native API calls on windows machines, no voodoo, using these calls u can amongst other things, create controls and ( finally ) present a native looking windows interface to your PHP scripts, you do not need any knowledge of the windows API to make use of winbinder, it's functions are geared toward php users and it's a fantastically written and documented extension.
phpCompile is written by me, to turn winbound ( or indeed, ANY php ) into windows executables, able to execute on any windows platform above windows 98 WITHOUT that machine having php installed. It uses the php embeeded sapi to create the executables, no voodoo, php is meant to do this ...
Yes, an exe out of php, good isn't it ...
archive above is source to an application, I don't think I included the exe, you should do that as part of the learning process .... the screenshot is the executing exe packed with phpCompile v1
iBrightDev September 6th, 2007, 14:11 joe, how the heck do you use the phpcompile? every time i try to load the program, the command prompt flashes, and then disappears instantly. :S
Mentok September 6th, 2007, 14:41 Joe, I'm trying to compile that uTube programme from the source files you gave me, but when I open the programme it flashes for a millisecond and closes. What's up?
krakjoe September 6th, 2007, 14:43 @MCT, just like any other console executable, if you need to force it to stay open call system("PAUSE"); at the end of execution, otherwise execute it properly from a console ( cmd ) ...
@Colin, on IM
NOTE TO ALL : If a application depends on an extension, you must add that extension to the project with phpcompile, this application requires both curl and winbinder ... furthermore curl requires libeay32.dll and ssleay32.dll - this is a restriction of cURL, NOT phpCompile, or winbinder
http://krakjoe.com/temp/uTube-exe.zip
iBrightDev September 6th, 2007, 16:15 i think it wont work because of the way the system admin has the computers set up at work
i will see if i can get it to work at home instead
is your site down?
krakjoe September 6th, 2007, 16:16 what code are you trying to run ?? it should work on any system, it doesn't matter how it is setup because it has everything it needs to run inside the archive ( with the exception applications that use curl ) ....
iBrightDev September 6th, 2007, 16:19 i cant even do a cd c: to start trying to open anything
the drive shows as h: :S
there is no h drive. so, i think i am being blocked form doing anything in cmd.
krakjoe September 6th, 2007, 16:20 then put system("PAUSE"); at the end of the code your running and it'll stop the execution and keep the window till you press enter .... but yeah that's wierd, prolly best to leave it till you get home ...
iBrightDev September 6th, 2007, 16:25 that is it, i dont really know what you mean by what code am i running. i am trying to open you compile program because i wanted to compile the utube program, but, when i try to open the compile program, the windows closes immediately. so, how can i keep that window open? or, and i trying to compile it wrong?
krakjoe September 6th, 2007, 16:48 oh prolly then they have done something to stop you running software they do not know .... which is quite clever, leave it till your on a normal pc .....
iBrightDev September 6th, 2007, 17:27 yeah, i will try at home. if it does anything strange like that, i will let you know.
Chris L. November 28th, 2007, 15:39 Anyone have uTube.zip?
BrandonTheG November 29th, 2007, 16:14 Can you update the links on this please, thanks.
krakjoe November 29th, 2007, 16:18 phpCompile can be downloaded from http://interviolet.com the others are all lost, and I'll write some more examples when I have time to do so ... I think Colin might have some example winbinder code that he could contribute, he might even have utube.zip ....
Mentok November 29th, 2007, 16:24 I don't think I've kept it, I'll have a look though.
The best place to get examples is from www.winbinder.org, download the programme and look at the installed folders (should be one called "examples").
Darknight November 29th, 2007, 20:00 MCT might? he was trying to complie it?
krakjoe December 3rd, 2007, 19:42 I found a version of phpCompile-Beta v4.0.1 - the latest was 4.1.8 however this is the only one I can find ... still uses php5.2.1 and works with winbinder, although is probably quite buggy ...
http://interviolet.com/downloads/
------------------------------------------------
phpCompile v2 Beta 4.0.1 :: PHP Version : 5.2.1
Written by Joe Watkins - krakjoe.com
Thanks to Rubem Pechansky - winbinder.org
------------------------------------------------
Extensions loaded :
cipher - simple xor cipher extension
date - standard date extension
dl_memory - allows stub to load normal php extensions
pcre - standard pcre extension
standard - standard php extension
win32 - select functions from win32std
winbinder - latest winbinder extension
Arguments Required :
-main|m Main script for project
Optional Arguments :
-project|p Project sources
-include|I Pack extra includes from directory
-add|a Add file to exe
-output|o default : $main.exe ( without .php )
-ext|e Add ext to executable
-ico Icon for executable
-ignore|i Ignore files matching pattern
-w Use windows subsystem
-c Use console subsystem
-subsystem console|windows, default : console
Information Arguments :
-iv Print phpCompile version
-ie Print PHP version
-ic Dump constants to stdin
-if Dump functions to stdin
-io Dump classes to stdin
Integration Arguments :
@serial Takes a base64_encode()'d array
~C:\inifile Takes location of ini file
Some example usage :
phpCompile -c -m=myscript.php
Will pack myscript.php into a console executable by itself named myscript.exe
phpCompile -w -p=ProjectSources -m=ProjectMain.php
Will pack all files in ProjectSources into an executable named ProjectMain.exe
with ProjectMain.php as main script
phpCompile -m=myscript
Will pack myscript.php(w) into a console executable by itself named myscript.exe
phpCompile -m=myscript -I=C:\winbinder\phpcode\include -w
Will pack all of winbinders includes, so you can include( 'winbinder.php' );
and set the main script to myscript.php(w) in an executable named myscript.exe using
the windows subsystem
phpCompile -m=myscript -a=C:\snippets\mysnippet.php
Will make an exe named myscript.exe, set main to myscript.php(w) and include mysnippet.php
so you can include('mysnippet.php');
phpCompile -p=myproject -i=.bmp -m=main
Will make an exe named main.exe, set the main script to main.php(w), all files from myproject
will be packed into the exe, except for those mathing .bmp
Notes :
You may omit .php or .phpw from your main script, phpCompile will search for .php first then .phpw
If you specify a project directory, your main script is expected to be found inside that directory
You can use (almost) any extension compatiable with php-5.2.1, download the windows binaries from php.net
Parameters you can use more than once per operation :
-include -I
-add -a
-ignore -i
-ext -e
About -add :
Files you specify here will be available in your executable at the "root" of the php source structure, so for example
if you add C:\snippets\highlight_c_source.php you can access it in your scripts with include( 'highlight_c_source.php' );
About -include :
Directories you specify here will be packed into the executable recursively, the same as -project directory, only you can
use as many as you want, paths will be relative to the -include
About -am :
Manifest update tool, usage :
phpCompile -am C:\projects\mine\myFile.exe C:\projects\mine\myFile.exe.manifest
Use this tool AT YOUR OWN RISK
As of now, that's it folks, be back soon, and for god sake report bugs.
Forever coding krakjoe........
PS Wine can execute this version of phpCompile-Beta, it cannot execute winbinder code though ... that relies to much on the winapi and phpCompile does not ( too much ) ... wine can also execute the executables it creates on linux ...
cyrus9 May 30th, 2009, 00:30 I just installed the WinBinder and tried the sample programs that came with that, its a good tool. I now finally found a way to create applications without compiling in one of my favorite programming language.
Thanks!
|
|