Hi,
I have an extension that includes code to use the common dialog boxes
provided by Win32, explicitly a call to GetOpenFileName().
This is intended for use in command line PHP scripts for selecting files to
work on etc.
Under PHP 4.1.1 this worked fine, the open file dialog boxes would work
perfectly. Since upgrading to 4.3.3, it has now stopped working.
The basic function which shows this problem is as follows:
ZEND_FUNCTION(test_open_file_box)
{
OPENFILENAME ofn;
char *filename = new char[3000];
filename[0] = '\0';
char *filter = new char[2000];
filter[0] = '\0';
char *title = new char[2000];
title[0] = '\0';
ofn.lStructSize = sizeof(ofn);
ofn.hwndOwner = NULL;
ofn.hInstance = NULL;
ofn.lpstrFilter = filter;
ofn.lpstrCustomFilter = NULL;
ofn.nMaxCustFilter = 0;
ofn.nFilterIndex = 0;
ofn.lpstrFile = filename;
ofn.nMaxFile = 2999;
ofn.lpstrFileTitle = NULL;
ofn.nMaxFileTitle = 0;
ofn.lpstrInitialDir = NULL;
ofn.lpstrTitle = title;
ofn.Flags = OFN_FILEMUSTEXIST;
ofn.nFileOffset = 0;
ofn.nFileExtension = 0;
ofn.lpstrDefExt = NULL;
ofn.lCustData = NULL;
ofn.lpfnHook = NULL;
ofn.lpTemplateName = NULL;
BOOL bResult = ::GetOpenFileName(&ofn);
DWORD dwLastError = CommDlgExtendedError();
if (bResult)
{
RETURN_TRUE;
}
else
{
RETURN_LONG(dwLastError);
}
}
This has been stripped down to the bare essentials that show this problem.
If a script is then written to call this function, under PHP 4.1.1 a Win32
dialog box appears. Under PHP 4.3.3 nothing appears but you do see an icon
for the dialog box in the task list you get when pressing ALT-TAB, you then
have to kill php to do anything else.
This occurs when running the script using either the CLI or CGI executables.
However the strange thing is when I run the script through Apache using PHP
as a module (and the Apache service set to 'Allow interaction with the
Desktop') the dialog box appears correctly.
I've been struggling with this for a few days now, if anybody knows why this
would have stopped working please help!
Thanks
Pete Dishman
PS. (It's a C++ PHP extension, and I'm running on Win2000)
Hi,
As Frank suggested, I tried using php_win.exe to call my test script with
and I still got exactly the same results, namely the dialog boxes would not
appear.
In my extension I have other functions that wrap things such as the Win32
MessageBox() functions and the 'Browse for a folder' function and these all
still work correctly. It is just the calls to GetOpenFileName and
GetSaveFileName that have stopped working since I upgraded to PHP 4.3.3
If anyone knows of anything that I could try or of anything significant that
has changed since 4.1.1 I would be very grateful as I don't want to have to
do without these functions.
Cheers,
Pete Dishman
Hi Pete,
I don't know why it stopped working, but you can try to use the
php_win.exe wrapper we use with PHP-GTK. Just copy the attached file (or
download it from http://kromann.info/php4-gtk.php) to the directory where
php.exe is installed and then call php_win.exe with your script as a
parameter.
Caling php_win.exe will launch php.exe as a windos process and not as a
command line process.
- Frank