PHP 5.3 + WinBinder -- SUCCESS

Specialized forum concerning the development and building of the WinBinder library.

Moderator: rubem

PHP 5.3 + WinBinder -- SUCCESS

Postby alecgorge » Thu Dec 03, 2009 2:15 am

I have gotten WinBinder to compile successfully on PHP 5.3. I have already gotten Win32std to compile, so WinBinder is the last part I need to complete to make complete PHP Windows Apps.

However, the problem is that PHP throws this warning every time a event is called and wb_set_handler returns FALSE:

Code: Select all
PHP Warning:  wb_main_loop(): User function call failed in C:\Path\To\File.php on line 52


I thought someone here might be able to steer me in the right direction on this problem I am having. I have attached my csource directory and the resulting dll.

I have narrowed the problem down to the function AssignHandlerToTabs in wb\wb_control_tab.c. Even though I fixed the 60 other issues that have cause WinBinder not to compile on PHP 5.3, this one has had me stuck for over a month.

I am using Visual C++ 2008 to edit and compile. I can attach my VC++ project if you want.


My WinBinder.dll : http://www.mediafire.com/download.php?wzzweuxazn3
My csource folder: http://www.mediafire.com/download.php?ojn3nhwq112
My iconv.lib (needed for compiling) : http://www.mediafire.com/download.php?zftzngjhdym

The contents of one of my test files:
Code: Select all
<?php

/*******************************************************************************

WINBINDER - A native Windows binding for PHP

Copyright © 2004-2005 Hypervisual - see LICENSE.TXT for details
Author: Rubem Pechansky (http://www.hypervisual.com/winbinder/contact.php)

Code sample: Mini-calculator application

*******************************************************************************/

//------------------------------------------------------------ SYSTEM PARAMETERS

define("PATH_SCRIPT",   dirname(__FILE__) . "/");
define("PATH_DATA",     PATH_SCRIPT);
define("PATH_INC",      PATH_SCRIPT . "include/");
define("PATH_RES",      PATH_SCRIPT . "resources/");

//----------------------------------------------------------------- DEPENDENCIES

include PATH_INC . "winbinder.php";

//-------------------------------------------------------------------- CONSTANTS

define("APPNAME",   "WinBinder Calculator");    // Application name
define("BLANK",     "blank");

//----------------------------------------------------------------- DEPENDENCIES

//------------------------------------------------------------- GLOBAL VARIABLES

/*
$newnumber = BLANK;
$memory = 0;
$display = "";
$number1 = "";
$number2 = "";
$opvalue = "";
}*/

//-------------------------------------------------------------- EXECUTABLE CODE

// Create main window from RC template

eval(parse_rc(file_get_contents(PATH_SCRIPT . "calc.rc"), '$mainwin', null, 'PopupWindow'));

// Set main window handler and enter application loop

var_dump(wb_set_handler($mainwin, "process_main"));
wb_main_loop();

//-------------------------------------------------------------------- FUNCTIONS

// TODO: Calculator is not working properly
// TODO: Use keyboard to enter keys

// Ported and adapted from original JavaScript calculator by Steve Dulaney
// http://www.hmhd.com/steve

/* Process main window commands */

function process_main($window, $id)
{
    global $memory, $display;

    switch($id) {

        case IDCLOSE:           // Predefined constant
            wb_destroy_window($window);
            break;

        case IDC_DISPLAY:       // Does not process edit controls
            break;

        default:                // Process buttons
            $ctrl = wb_get_control($window, $id);
            if(wb_get_class($ctrl) != PushButton)
                break;
            $caption = trim(wb_get_text($ctrl));

            switch($caption) {

                // Numbers and decimal point

                case "1": case "2": case "3": case "4": case "5":
                case "6": case "7": case "8": case "9": case "0":
                case ".":
                    checknumber($caption);              break;

                // Basic operations

                case "+":
                    addbutton(1);                       break;
                case "-":
                    subbutton(1);                       break;
                case "×":
                    multbutton(1);                      break;
                case "÷":
                    divbutton(1);                       break;

                // Op buttons

                case "<":
                    backspace($display);                break;
                case "CE":
                    cecalc();                           break;
                case "C":
                    clearcalc();                        break;
                case "=":
                    equalbutton();                      break;

                // Advanced operations

                case "sqrt":
                    sqrtbutton();                       break;
                case "x²":
                    sqrbutton();                        break;
                case "%":
                    percentbutton();                    break;
                case "1/x":
                    recipbutton();                      break;
                case "+/-":
                    negatebutton();                     break;

                // Memory buttons

                case "M-":
                    memorysubtract($display);           break;
                case "M+":
                    memoryadd($display);                break;
                case "MR":
                    memoryrecall($memory);              break;
                case "MC":
                    memoryclear();                      break;

            } // switch($caption)
            break;
    } // switch($id)
}

function display($displaynumber)
{
    global $mainwin, $display, $memory;

    $display = (string)$displaynumber;
    wb_set_text(wb_get_control($mainwin, IDC_DISPLAY), $display);

    $memctrl = wb_get_control($mainwin, IDC_MEM);
    wb_set_visible($memctrl, $memory);
    if($memory)
        wb_refresh($memctrl);
}

function checknumber($answer)
{
    global $number1, $number2, $newnumber, $display;

    if($answer == ".") {
        $n = $display;
        if(strpos($n, '.')) {
            $answer = "";
        }
    }
    if($newnumber == TRUE) {
        $number2 .= $answer;
        display($number2);
    } else {
        if($newnumber == BLANK) {
            $number1 = $answer;
            $number2 = "";
            $newnumber = FALSE;
        } else {
            $number1 .= $answer;
        }
        display($number1);

    }
}

function memoryclear()
{
    global $memory, $display;

    $memory = 0;
    display($display);
}

function memoryrecall($answer)
{
    global $newnumber, $number1, $number2;

    if($newnumber != BLANK) {
        $number2 .= $answer;
    } else {
        $number1 = $answer;
    }
    $newnumber = BLANK;
    display($answer);
}

function memorysubtract($answer)
{
    global $memory, $display;

    $memory = $memory - (double)$answer;
    display($display);
}

function memoryadd($answer)
{
    global $memory, $newnumber, $display;

    $memory = $memory + (double)$answer;
    $newnumber = BLANK;
    display($display);
}

function clearcalc()
{
    global $newnumber, $number1, $number2;

    unset($GLOBALS['number1']);
    unset($GLOBALS['number2']);
    unset($GLOBALS['newnumber']);
    display("");
}

function backspace($answer)
{
    global $number1, $number2;

    $answerlength = strlen($answer);
    $answer = substr($answer, 0, $answerlength - 1);

    if($number2 != "") {
        $number2 = (string)$answer;
        display($number2);
    } else {
        $number1 = (string)$answer;
        display($number1);
    }
}

function cecalc()
{
    global $number2, $newnumber;

    $number2 = "";
    $newnumber = TRUE;
    display("");
}

function addbutton($x)
{
    global $number1, $number2, $newnumber, $opvalue;

    if($x == 1)
        equalbutton();
    if($number2 != "") {
        $number1 = (double)$number1 + (double)$number2;

    }
    $newnumber = TRUE;
    $opvalue = '+';
    display($number1);


}

function subbutton($x)
{
    global $number1, $number2, $newnumber, $opvalue;

    if($x == 1)
        equalbutton();
    if($number2 != "") {
        $number1 = (double)$number1 - (double)$number2;
    }
    $newnumber = TRUE;
    $opvalue = '-';
    display($number1);
}

function multbutton($x)
{
    global $number1, $number2, $newnumber, $opvalue;

    if($x == 1)
        equalbutton();
    if($number2 != "") {
        $number1 = (double)$number1 * (double)$number2;
    }
    $newnumber = TRUE;
    $opvalue = '*';
    display($number1);
}

function divbutton($x)
{
    global $number1, $number2, $newnumber, $opvalue;

    if($x == 1)
        equalbutton();
    if($number2 != "") {
        $number1 = (double)$number1 / (double)$number2;
    }
    $newnumber = TRUE;
    $opvalue = '/';
    display($number1);
}

function sqrbutton()
{
    global $number1, $newnumber;

    $number1 = $number1 * $number1;
    $newnumber = BLANK;
    display($number1);
}

function sqrtbutton()
{
    global $number1, $newnumber;

    $number1 = sqrt($number1);
    $newnumber = BLANK;
    display($number1);
}

function percentbutton()
{
    global $number1, $number2, $newnumber;

    if($newnumber != BLANK) {
        $number2 *= 0.01;
        $newnumber = BLANK;
        display($number2);
    }
}

function recipbutton()
{
    global $number1, $newnumber;

    $number1 = 1 / $number1;
    $newnumber = BLANK;
    display($number1);
}

function negatebutton()
{
    global $number1, $newnumber;

    $number1 = -(double)$number1;
    $newnumber = FALSE;
    display($number1);
}

function equalbutton()
{
    global $number1, $number2, $opvalue;

    if($opvalue == '+')
        addbutton(0);
    if($opvalue == '-')
        subbutton(0);
    if($opvalue == '*')
        multbutton(0);
    if($opvalue == '/')
        divbutton(0);
    $number2 = "";
    $opvalue = "";

}


//------------------------------------------------------------------ END OF FILE

?>
phpack, the best PHP compiler ever (unicode support): http://bit.ly/d1PXGF
alecgorge
 
Posts: 209
Joined: Thu Dec 03, 2009 2:05 am

Re: [ALMOST] PHP 5.3 + WinBinder

Postby frantik » Mon Dec 07, 2009 10:39 am

thats great you're working on 5.3.. sorry i don't have any advice :(
frantik
 
Posts: 568
Joined: Tue Mar 22, 2005 7:17 am
Location: California

Re: [ALMOST] PHP 5.3 + WinBinder

Postby frantik » Mon Dec 07, 2009 6:37 pm

also please note if you're building a new DLL that line 308 of lowlevel.c needs to be uncommented to prevent memory leaks when using the winapi

see this thread: viewtopic.php?f=3&t=868&start=0
frantik
 
Posts: 568
Joined: Tue Mar 22, 2005 7:17 am
Location: California

Re: [ALMOST] PHP 5.3 + WinBinder

Postby alecgorge » Mon Dec 07, 2009 9:26 pm

Yeah I happened to see that.

I have that uncommented.

Thanks for checking though, no one likes memory leaks!
phpack, the best PHP compiler ever (unicode support): http://bit.ly/d1PXGF
alecgorge
 
Posts: 209
Joined: Thu Dec 03, 2009 2:05 am

Re: [ALMOST] PHP 5.3 + WinBinder

Postby frantik » Fri Dec 11, 2009 2:04 am

:mrgreen: great

i have been meaning to take a look at this but havent had the time.

php 5.3 compatibility is something i would like to achieve too so i can release a new phc-win that works with 5.3
frantik
 
Posts: 568
Joined: Tue Mar 22, 2005 7:17 am
Location: California

Re: [ALMOST] PHP 5.3 + WinBinder

Postby alecgorge » Fri Dec 11, 2009 3:18 am

There is just something wrong in the way it is attaching the custom user functions. I just can't figure out what.
phpack, the best PHP compiler ever (unicode support): http://bit.ly/d1PXGF
alecgorge
 
Posts: 209
Joined: Thu Dec 03, 2009 2:05 am

Re: [ALMOST] PHP 5.3 + WinBinder

Postby frantik » Sun Dec 13, 2009 2:31 am

i got it to compile, but it's crashing on wb_main_loop()
frantik
 
Posts: 568
Joined: Tue Mar 22, 2005 7:17 am
Location: California

Re: [ALMOST] PHP 5.3 + WinBinder

Postby frantik » Sun Dec 13, 2009 2:59 am

SUCCESS! :D

Download WB 0.46.191 compatible with PHP 5.3.1

The only mofications I needed to make the WB source code was to change zend_is_callable and add TSRMLS_CC to the end of the call (as seen in the php 5.3.1 source code, which is where I got the idea to use it)

zend_is_callable(fname, 0, &pszFName TSRMLS_CC)

in your code you have

zend_is_callable(fname, 0, &pszFName, 0) which doesnt work correctly
frantik
 
Posts: 568
Joined: Tue Mar 22, 2005 7:17 am
Location: California

Re: [ALMOST] PHP 5.3 + WinBinder

Postby alecgorge » Sun Dec 13, 2009 3:26 am

Hooray! How did you compile? VC++ 2008?

Did you modify my source code or Rubem's?

Also, do you have Skype because I think it would be easier for us to use the IM and then post a summary here so that people don't have to wade through a bunch of stuff to find the answer.
phpack, the best PHP compiler ever (unicode support): http://bit.ly/d1PXGF
alecgorge
 
Posts: 209
Joined: Thu Dec 03, 2009 2:05 am

Re: [ALMOST] PHP 5.3 + WinBinder

Postby alecgorge » Sun Dec 13, 2009 3:48 am

You have very different source code than me. How did you get yours? I just download mine from the sources on the main page.
phpack, the best PHP compiler ever (unicode support): http://bit.ly/d1PXGF
alecgorge
 
Posts: 209
Joined: Thu Dec 03, 2009 2:05 am

Re: [ALMOST] PHP 5.3 + WinBinder

Postby alecgorge » Sun Dec 13, 2009 4:05 am

Hooray! I have compiled it for VC6 Binaries!

Now Frantik, I will just statically compile it into a php5ts.dll for you so that we can have PHC-WIN working nicely again!

Also, how important do you feel that cURL is to include because I have had trouble statically compiling that.

In any case, I have uploaded both version of the dll to mediafire for safekeeping:
VC6: http://www.mediafire.com/?3g2dwayg4zm
VC9: http://www.mediafire.com/?nyzmjvy0mme
phpack, the best PHP compiler ever (unicode support): http://bit.ly/d1PXGF
alecgorge
 
Posts: 209
Joined: Thu Dec 03, 2009 2:05 am

Re: [ALMOST] PHP 5.3 + WinBinder

Postby frantik » Sun Dec 13, 2009 4:15 am

alecgorge wrote:You have very different source code than me. How did you get yours? I just download mine from the sources on the main page.


i'm not 100% sure.. I used the same files that I used to make a previous version of the DLL.. the folder was named 0.46.0 in csource. i think it's actually the 0.46.189 snapshot though

Now Frantik, I will just statically compile it into a php5ts.dll for you so that we can have PHC-WIN working nicely again!


COOL.. how do you do that? also include winstd32 bcompiler if you can please :)

also if you know about VC++ options, the DLL i posted seems to take a seconds to load up the winbinder program, while the 5.2.6 version dll i have does not take very long to load up. i dont know what is different.
frantik
 
Posts: 568
Joined: Tue Mar 22, 2005 7:17 am
Location: California

Re: [ALMOST] PHP 5.3 + WinBinder

Postby rubem » Mon Dec 14, 2009 12:16 am

Great work!!! Congrats Frantik and Alecgorge, I really appreciate what you have done. WinBinder lives :P

You may send me the source code and binaries whenever you want, I'll gladly make them available on the web site.
Rubem Pechansky
The WinBinder Guy
User avatar
rubem
Site Admin
 
Posts: 731
Joined: Fri Jan 07, 2005 2:15 pm
Location: Porto Alegre, Brazil

Re: PHP 5.3 + WinBinder -- SUCCESS

Postby alecgorge » Mon Dec 14, 2009 2:42 am

Synopsis for download happy people

The Long Story
Ok. I have 2 different WinBinder binaries and 2 different php5ts.dll 's with WinBinder, win32std and a few other goodies built in.

The PHP 5.3.1 Compatible WinBinder DLL's
First off, the only difference between the WinBinder binaries is the fact that one is compressed with UPX and one isn't. The UPX compressed one weighs in at 47kb, while the uncompressed version weighs in at 102kb. There is no noticeable difference in start times so I recommend the UPX compressed one.

I have only been able to test these on my computer so I would like at least a few others to test before we release them. I have Win7 64-bit. If you have a different OS, I implore you to test this.

The download includes UPX packed DLL's, nonpacked DLL's, and the source files. DOWNLOAD: http://www.mediafire.com/?w0jzqnvjhnr
The DLL's are VC9 only, which should be the only branch we maintain since VC6 is dying out and these PHP binaries aren't being used for Apache (which doesn't presently support PHP VC9) so everything works well.


The PHP 5.3.1 php5ts.dll with WinBinder statically built in
Both php5ts.dll packages include the following:
  • php.exe
  • php5embed.lib
  • php5ts.dll (compressed with UPX because I couldn't find any performance difference and the file is 35% of the normal size)
  • php5ts.lib
  • WinBinder statically compiled in
  • win32std statically compiled in

I call the first php5ts.dll, 'featherweight', because it contains less extensions than usual and is only 3,100 kb. Here are the extensions that are compiled statically (DOWNLOAD: http://www.mediafire.com/?ym2zrwdjhm2 ) :
Code: Select all
Array
(
    [0] => Core
    [1] => PDO
    [2] => Phar
    [3] => Reflection
    [4] => SPL
    [5] => SimpleXML
    [6] => com_dotnet
    [7] => ctype
    [8] => date
    [9] => filter
    [10] => ftp
    [11] => gd
    [12] => hash
    [13] => iconv
    [14] => json
    [15] => libxml
    [16] => mbstring
    [17] => mcrypt
    [18] => mhash
    [19] => pcre
    [20] => pdo_sqlite
    [21] => soap
    [22] => sockets
    [23] => standard
    [24] => tokenizer
    [25] => win32std
    [26] => winbinder
    [27] => xmlwriter
    [28] => zip
    [29] => zlib
)


I call the second 'full', it is 3,901 kb and has just about everything you could need (DOWNLOAD: http://www.mediafire.com/?miryiczj5jk ):
Code: Select all
Array
(
    [0] => Core
    [1] => PDO
    [2] => Phar
    [3] => Reflection
    [4] => SPL
    [5] => SQLite
    [6] => SimpleXML
    [7] => bcmath
    [8] => bcompiler
    [9] => bz2
    [10] => calendar
    [11] => com_dotnet
    [12] => ctype
    [13] => date
    [14] => dom
    [15] => ereg
    [16] => exif
    [17] => filter
    [18] => ftp
    [19] => gd
    [20] => gettext
    [21] => hash
    [22] => iconv
    [23] => json
    [24] => libxml
    [25] => mbstring
    [26] => mcrypt
    [27] => mhash
    [28] => mysql
    [29] => mysqli
    [30] => mysqlnd
    [31] => odbc
    [32] => openssl
    [33] => pcre
    [34] => pdo_mysql
    [35] => pdo_sqlite
    [36] => soap
    [37] => sockets
    [38] => sqlite3
    [39] => standard
    [40] => tokenizer
    [41] => wddx
    [42] => win32std
    [43] => winbinder
    [44] => xml
    [45] => xmlreader
    [46] => xmlwriter
    [47] => zip
    [48] => zlib
)


How I built these PHP dlls
I mostly followed these instructions: http://wiki.php.net/internals/windows/stepbystepbuild

All directories in this block are relative to the PHP source directory (it has configure.js in it)

The only exceptions are that I just downloaded php 5.3.1 VC9 stable from http://windows.php.net/download/ instead of a snapshot.

I then copied the WinBinder sources (above) and the win32std sources (http://www.mediafire.com/download.php?t3dwzjj3xx0) into ext/

I put every single one of these: http://pecl2.php.net/downloads/php-wind ... s/VC9/x86/ in the respective ../deps folder

After I my configure command I opened the Makefile and searched for '/out:' at the end of the line of the first recurrence I put:
Code: Select all
kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib comctl32.lib winmm.lib


I then ran nmake and everything output to the Release_TS folder.

Conclusion
I would be happy to build any combination of extensions (including PECL) for anybody, just post here or PM me.

I am happy I can now start writing PHP again instead of C. I hope frantik releases his new version of PHC-WIN soon so I can start distributing things.

Hopes for the future
I can't get cURL or fileinfo to statically compile into PHP and I can't figure out why. I would like to figure this out and include cURL and fileinfo in a future php5ts.dll (help would be appreciated)
phpack, the best PHP compiler ever (unicode support): http://bit.ly/d1PXGF
alecgorge
 
Posts: 209
Joined: Thu Dec 03, 2009 2:05 am

Re: PHP 5.3 + WinBinder -- SUCCESS

Postby frantik » Mon Dec 14, 2009 5:32 am

Awesome! I will work on phc-win this week. I compiled a new EXE stub so it's just a matter of wrapping the code into it and all that jazz. i wish your featherweight DLL had bcompiler and bz2 (bz2 is needed for bcompiler) because then it could be used with phc-win, but the other dll isn't excessively large or anything

now the holy grail would be to compile these DLLS right into the EXE itself.. i don't want to ask too much though haha :oops:

Rubem, the code for the latest version is in the zip file i posted upthread if you want to post it.
frantik
 
Posts: 568
Joined: Tue Mar 22, 2005 7:17 am
Location: California

Next

Return to C Programming