cvs: pecl /win32std CREDITS README cpp_wrappers.cpp package.xml php_win32std.h registry.c res.c res_stream.c win32std.c win32std.dsp
/win32std/examples win32std.php

From: Date: Tue, 30 Dec 2003 10:42:10 +0000
Subject: cvs: pecl /win32std CREDITS README cpp_wrappers.cpp package.xml php_win32std.h registry.c res.c res_stream.c win32std.c win32std.dsp
/win32std/examples win32std.php
Groups: php.pecl.cvs 
Request: Send a blank email to pecl-cvs+get-636@lists.php.net to get a copy of this message
ecolinet Tue Dec 30 05:42:10 2003 EDT Added files: /pecl/win32std CREDITS README cpp_wrappers.cpp package.xml php_win32std.h registry.c res.c res_stream.c win32std.c win32std.dsp /pecl/win32std/examples win32std.php Log: Initial commit

Index: pecl/win32std/cpp_wrappers.cpp +++ pecl/win32std/cpp_wrappers.cpp /* +----------------------------------------------------------------------+ | PHP Version 4 | +----------------------------------------------------------------------+ | Copyright (c) 1997-2002 The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | | available at through the world-wide-web at | | http://www.php.net/license/3_0.txt. | | If you did not receive a copy of the PHP license and are unable to | | obtain it through the world-wide-web, please send a note to | | license@php.net so we can mail you a copy immediately. | +----------------------------------------------------------------------+ | Author: Eric COLINET <e.colinet@laposte.net> | +----------------------------------------------------------------------+ */ #include "shlobj.h" /* HICON GetSysFileIcon( const char * file, bool large ) { SHFILEINFO shInfo; if( SHGetFileInfo( file, 0, &shInfo, sizeof(SHFILEINFO), large?SHGFI_ICON|SHGFI_LARGEICON:SHGFI_ICON|SHGFI_SMALLICON)==0 ) return NULL; return shInfo.hIcon; } */ extern "C" int php_browse_for_folder( HWND wnd, const char * display, char path_buf[MAX_PATH] ) { BROWSEINFO binfo; LPITEMIDLIST itmlist; LPMALLOC pAlloc; binfo.hwndOwner= wnd; binfo.pidlRoot= NULL; binfo.pszDisplayName= path_buf; binfo.lpszTitle= display; // binfo.ulFlags= BIF_USENEWUI ; // VC7 binfo.ulFlags= 0; binfo.lpfn= NULL; binfo.lParam= 0; binfo.iImage= 0; itmlist= SHBrowseForFolder( &binfo ); path_buf[0]= 0; if( itmlist==NULL ) return 0; if( !SHGetPathFromIDList( itmlist, path_buf ) ) return 0; // A tester avec chemin de plus de 260 char // free itmlist SHGetMalloc( &pAlloc ); pAlloc->Free( itmlist ); pAlloc->Release(); return 1; } extern "C" int php_create_link(LPCSTR lpszPathObj, LPSTR lpszPathLink, LPSTR lpszArgs, LPSTR lpszDesc, LPSTR lpszWorkingDir) { HRESULT hres; IShellLink* psl; if( !lpszPathObj || !lpszPathLink || !*lpszPathObj || !*lpszPathLink ) return 0; // Get a pointer to the IShellLink interface. hres = CoCreateInstance(CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER, IID_IShellLink, (void**)&psl); if (SUCCEEDED(hres)) { IPersistFile* ppf; // Set the path to the shortcut target and add the // description. psl->SetPath(lpszPathObj); if( lpszDesc ) psl->SetDescription(lpszDesc); if( lpszArgs ) psl->SetArguments(lpszArgs); if( lpszWorkingDir ) psl-> SetWorkingDirectory(lpszWorkingDir); // Query IShellLink for the IPersistFile interface for saving the // shortcut in persistent storage. hres = psl->QueryInterface( IID_IPersistFile, (void**)&ppf); if (SUCCEEDED(hres)) { WORD wsz[MAX_PATH]; // Ensure that the string is ANSI. MultiByteToWideChar(CP_ACP, 0, lpszPathLink, -1, wsz, MAX_PATH); // Save the link by calling IPersistFile::Save. hres = ppf->Save( wsz, TRUE); ppf->Release(); } psl->Release(); } if( SUCCEEDED(hres) ) return 1; else return 0; } Index: pecl/win32std/package.xml +++ pecl/win32std/package.xml <?xml version="1.0" encoding="ISO-8859-1" ?> <!DOCTYPE package SYSTEM "http://pear.php.net/dtd/package-1.0"> <package version="1.0"> <name>win32std</name> <summary>Access to some Win32 usefull API.</summary> <description>Contains: - RES (access to resource of .exe/.dll files on Win32) - RES stream wrapper for reading. Compatible with the res protocol defined by MS - REGISTRY access - Common Win32 dialogs (open/save file, open dir, message boxes) - Wrapper for some standard function (win_shell_execute, win_play_wav, win_beep, win_create_link)</description> <maintainers> <maintainer> <user>ecolinet</user> <name>Eric Colinet</name> <email>e.colinet@laposte.net</email> <role>lead</role> </maintainer> <maintainer> <user>fmk</user> <name>Frank M. Kromann</name> <email>frank@kromann.info</email> <role>developer</role> </maintainer> </maintainers> <release> <version>1.0</version> <date>2003-11-19</date> <license>PHP</license> <state>beta</state> <notes>First release</notes> <filelist> <file role="src" name="win32std.dsp"/> <file role="src" name="php_win32std.h"/> <file role="src" name="win32std.c"/> <file role="src" name="res.c"/> <file role="src" name="registry.c"/> <file role="src" name="res_stream.c"/> <file role="src" name="cpp_wrappers.cpp"/> <file role="doc" name="CREDITS"/> <file role="doc" name="README"/> <dir name="examples" role="doc" baseinstalldir="/"> <file role="doc" name="win32std.php"/> </dir> </filelist> </release> </package> Index: pecl/win32std/php_win32std.h +++ pecl/win32std/php_win32std.h /* +----------------------------------------------------------------------+ | PHP Version 4 | +----------------------------------------------------------------------+ | Copyright (c) 1997-2002 The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | | available at through the world-wide-web at | | http://www.php.net/license/3_0.txt. | | If you did not receive a copy of the PHP license and are unable to | | obtain it through the world-wide-web, please send a note to | | license@php.net so we can mail you a copy immediately. | +----------------------------------------------------------------------+ | Author: Eric COLINET <e.colinet@laposte.net> | | Author: Frank M. Kromann <frank@kromann.info> | +----------------------------------------------------------------------+ */ #ifndef PHP_WIN32STD_H #define PHP_WIN32STD_H #include "php.h" #include "php_ini.h" #include "zend_list.h" #include "ext/standard/info.h" extern zend_module_entry win32std_module_entry; #define phpext_win32std_ptr &win32std_module_entry #ifdef PHP_WIN32 #define PHP_WIN32STD_API __declspec(dllexport) #else #define PHP_WIN32STD_API #endif #ifdef ZTS #include "TSRM.h" #endif #define MAX_SUBKEY_LEN 512 extern int le_res_resource; #define le_res_resource_name "RES resource" extern int le_key; #define le_key_resource_name "Registry hKey" typedef struct _registry_hkey { HKEY hKey; } registry_hkey; void php_hkey_close(zend_rsrc_list_entry *rsrc TSRMLS_DC); #define WIN32_STRERROR_BUFFER_LEN 256 const char * win32_strerror( char * buffer, long buffer_len); /* Res functions */ ZEND_MINIT_FUNCTION(win32std); ZEND_MSHUTDOWN_FUNCTION(win32std); ZEND_RINIT_FUNCTION(win32std); ZEND_RSHUTDOWN_FUNCTION(win32std); ZEND_MINFO_FUNCTION(win32std); /* Res functions */ PHP_FUNCTION(res_get); PHP_FUNCTION(res_list); PHP_FUNCTION(res_list_type); PHP_FUNCTION(res_open); PHP_FUNCTION(res_close); PHP_FUNCTION(res_set); /* Res stream */ php_stream *php_res_stream_open(php_stream_wrapper *wrapper, char *path, char *mode, int options, char **opened_path, php_stream_context *context STREAMS_DC TSRMLS_DC); extern php_stream_ops php_res_stream_ops; extern php_stream_wrapper php_res_stream_wrapper; void _php_res_destruction_handler(zend_rsrc_list_entry *rsrc TSRMLS_DC); /* Win32 wrapper functions */ PHP_FUNCTION(win_shell_exec); PHP_FUNCTION(win_play_wav); PHP_FUNCTION(win_beep); PHP_FUNCTION(win_create_link); PHP_FUNCTION(win_message_box); PHP_FUNCTION(win_browse_folder); PHP_FUNCTION(win_browse_file); /* Registry functions */ PHP_FUNCTION(reg_create_key); PHP_FUNCTION(reg_open_key); PHP_FUNCTION(reg_close_key); PHP_FUNCTION(reg_enum_key); PHP_FUNCTION(reg_enum_value); PHP_FUNCTION(reg_get_value); PHP_FUNCTION(reg_set_value); /* Win32 STD API functions that call C++ Object */ int php_browse_for_folder( HWND wnd, const char * display, char path_buf[MAX_PATH] ); int php_create_link(LPCSTR lpszPathObj, LPSTR lpszPathLink, LPSTR lpszArgs, LPSTR lpszDesc, LPSTR lpszWorkingDir); /* Declare any global variables you may need between the BEGIN and END macros here: ZEND_BEGIN_MODULE_GLOBALS(win32std) int global_value; char *global_string; ZEND_END_MODULE_GLOBALS(win32std) */ /* In every utility function you add that needs to use variables in php_win32std_globals, call TSRM_FETCH(); after declaring other variables used by that function, or better yet, pass in TSRMG_CC after the last function argument and declare your utility function with TSRMG_DC after the last declared argument. Always refer to the globals in your function as WIN32STD_G(variable). You are encouraged to rename these macros something shorter, see examples in any other php module directory. */ #ifdef ZTS #define WIN32STD_G(v) TSRMG(win32std_globals_id, zend_win32std_globals *, v) #else #define WIN32STD_G(v) (win32std_globals.v) #endif #endif /* PHP_WIN32STD_H */ Index: pecl/win32std/registry.c +++ pecl/win32std/registry.c /* +----------------------------------------------------------------------+ | PHP Version 4 | +----------------------------------------------------------------------+ | Copyright (c) 1997-2002 The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | | available at through the world-wide-web at | | http://www.php.net/license/3_0.txt. | | If you did not receive a copy of the PHP license and are unable to | | obtain it through the world-wide-web, please send a note to | | license@php.net so we can mail you a copy immediately. | +----------------------------------------------------------------------+ | Author: Frank M. Kromann <frank@kromann.info> | +----------------------------------------------------------------------+ */ #ifdef HAVE_CONFIG_H #include "config.h" #endif #include "php.h" #include "php_ini.h" #include "ext/standard/info.h" #include "php_win32std.h" /* True global resources - no need for thread safety here */ /*static*/ int le_key; void php_hkey_close(zend_rsrc_list_entry *rsrc TSRMLS_DC) { registry_hkey *hKey = (registry_hkey *)rsrc->ptr; RegCloseKey(hKey->hKey); efree(hKey); } static HKEY _registry_get_hkey(zval **zhKey TSRMLS_DC) { HKEY hKey; switch (Z_TYPE_PP(zhKey)) { case IS_LONG : switch (Z_LVAL_PP(zhKey)) { case 0 : hKey = HKEY_CLASSES_ROOT; break; case 1 : hKey = HKEY_CURRENT_CONFIG; break; case 2 : hKey = HKEY_CURRENT_USER; break; case 3 : hKey = HKEY_LOCAL_MACHINE; break; case 4 : hKey = HKEY_USERS; break; } break; case IS_RESOURCE : { registry_hkey *open_hkey; open_hkey = (registry_hkey *) zend_fetch_resource(zhKey TSRMLS_CC, -1, le_key_resource_name, NULL, 1, le_key); if (open_hkey) hKey = open_hkey->hKey; else hKey = NULL; } break; default : hKey = NULL; break; } return hKey; } /* {{{ proto void reg_close_key(resource hKey) */ PHP_FUNCTION(reg_close_key) { zval *zhKey; registry_hkey *reg_hkey; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &zhKey) == FAILURE) { return; } ZEND_FETCH_RESOURCE(reg_hkey, registry_hkey *, &zhKey, -1, le_key_resource_name, le_key); zend_list_delete(Z_RESVAL_P(zhKey)); } /* }}} */ /* {{{ proto resource reg_create_key(mixed hKey, string subkey [, int samDesired = KEY_ALL_ACCESS]) */ PHP_FUNCTION(reg_create_key) { zval *zhKey; long samDesired_arg = 0; char *arg = NULL; int arg_len; HKEY hKey; HKEY hkResult; REGSAM samDesired = KEY_ALL_ACCESS; DWORD dwDisposition; LONG rc; char buffer[WIN32_STRERROR_BUFFER_LEN]; registry_hkey *reg_hkey; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zs|l", &zhKey, &arg, &arg_len, &samDesired_arg) == FAILURE) { return; } hKey = _registry_get_hkey(&zhKey TSRMLS_CC); rc = RegCreateKeyEx(hKey, arg, 0, NULL, REG_OPTION_NON_VOLATILE, samDesired, NULL, &hkResult, &dwDisposition); if (rc != ERROR_SUCCESS) { zend_error( E_WARNING, "Can't create registry key: %s", win32_strerror(buffer, WIN32_STRERROR_BUFFER_LEN) ); RETURN_FALSE; } else { reg_hkey = (registry_hkey *) emalloc(sizeof(registry_hkey)); reg_hkey->hKey = hkResult; ZEND_REGISTER_RESOURCE(return_value, reg_hkey, le_key); } } /* }}} */ /* {{{ proto mixed reg_enum_key(mixed hKey[, int index=1]) */ PHP_FUNCTION(reg_enum_key) { zval *zhKey; long index = -1; char buf[MAX_SUBKEY_LEN]; DWORD buf_len = MAX_SUBKEY_LEN; FILETIME LastWriteTime; HKEY hKey; LONG rc; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z|l", &zhKey, &index) == FAILURE) { return; } hKey = _registry_get_hkey(&zhKey TSRMLS_CC); if( index>-1 ) { rc = RegEnumKeyEx(hKey, index, buf, &buf_len, NULL, NULL, NULL, &LastWriteTime); if (rc != ERROR_SUCCESS) { if( rc!=ERROR_NO_MORE_ITEMS ) zend_error( E_WARNING, "Can't enum registry keys: %s", win32_strerror(buf, MAX_SUBKEY_LEN) ); RETURN_FALSE; } else { RETURN_STRINGL(buf, buf_len, 1); } } // Return array array_init(return_value); for( index= 0, buf_len = MAX_SUBKEY_LEN; (rc= RegEnumKeyEx(hKey, index, buf, &buf_len, NULL, NULL, NULL, &LastWriteTime))==ERROR_SUCCESS; index++ ) { add_next_index_string( return_value, buf, buf_len+1 ); buf_len = MAX_SUBKEY_LEN; } if( rc!=ERROR_NO_MORE_ITEMS ) zend_error( E_WARNING, "Can't enum registry keys: %s", win32_strerror(buf, MAX_SUBKEY_LEN) ); } /* }}} */ /* {{{ proto mixed reg_enum_value(mixed hKey[, int index=-1]) */ PHP_FUNCTION(reg_enum_value) { zval *zhKey; long index = -1; char buf[MAX_SUBKEY_LEN]; DWORD buf_len = MAX_SUBKEY_LEN; HKEY hKey; LONG rc; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z|l", &zhKey, &index) == FAILURE) { return; } hKey = _registry_get_hkey(&zhKey TSRMLS_CC); if( index>-1 ) { rc = RegEnumValue(hKey, index, buf, &buf_len, NULL, NULL, NULL, NULL); if (rc != ERROR_SUCCESS) { if( rc!=ERROR_NO_MORE_ITEMS ) zend_error( E_WARNING, "Can't enum registry values: %s", win32_strerror(buf, MAX_SUBKEY_LEN) ); RETURN_FALSE; } else { RETURN_STRINGL(buf, buf_len, 1); } } // Return array array_init(return_value); for( index= 0, buf_len = MAX_SUBKEY_LEN; (rc= RegEnumValue(hKey, index, buf, &buf_len, NULL, NULL, NULL, NULL))==ERROR_SUCCESS; index++ ) { add_next_index_string( return_value, buf, buf_len+1 ); buf_len = MAX_SUBKEY_LEN; } if( rc!=ERROR_NO_MORE_ITEMS ) zend_error( E_WARNING, "Can't enum registry values: %s", win32_strerror(buf, MAX_SUBKEY_LEN) ); } /* }}} */ /* {{{ proto resource reg_open_key(mixed hKey, string subkey [, int samDesired = KEY_ALL_ACCESS]) */ PHP_FUNCTION(reg_open_key) { zval *zhKey; long samDesired_arg = 0; char *arg = NULL; int arg_len; HKEY hKey; HKEY hkResult; REGSAM samDesired = KEY_ALL_ACCESS; LONG rc; char buffer[WIN32_STRERROR_BUFFER_LEN]; registry_hkey *reg_hkey; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zs|l", &zhKey, &arg, &arg_len, &samDesired_arg) == FAILURE) { return; } hKey = _registry_get_hkey(&zhKey TSRMLS_CC); rc = RegOpenKeyEx(hKey, arg, 0, samDesired, &hkResult); if (rc != ERROR_SUCCESS) { zend_error( E_WARNING, "Can't open registry key: %s", win32_strerror(buffer, WIN32_STRERROR_BUFFER_LEN) ); RETURN_FALSE; } else { reg_hkey = (registry_hkey *) emalloc(sizeof(registry_hkey)); reg_hkey->hKey = hkResult; ZEND_REGISTER_RESOURCE(return_value, reg_hkey, le_key); } } /* }}} */ /* {{{ proto bool reg_set_value(mixed hKey, string value_name, int type, mixed value) */ PHP_FUNCTION(reg_set_value) { zval *zhKey, *value; long value_type = REG_DWORD; char *value_name = NULL; int value_len; HKEY hKey; CONST BYTE *lpData; // address of value data DWORD cbData; // size of value data LONG rc; char buffer[WIN32_STRERROR_BUFFER_LEN]; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zslz", &zhKey, &value_name, &value_len, &value_type, &value) == FAILURE) { return; } hKey = _registry_get_hkey(&zhKey TSRMLS_CC); switch (value_type) { case REG_DWORD : convert_to_long(value); lpData = (BYTE *)&Z_LVAL_P(value); cbData = sizeof(DWORD); break; case REG_EXPAND_SZ: case REG_SZ : convert_to_string(value); lpData = Z_STRVAL_P(value); cbData = Z_STRLEN_P(value) + 1; break; default : zend_error( E_WARNING, "registry value type not handled" ); RETURN_FALSE; break; } rc = RegSetValueEx(hKey, value_name, 0, value_type, lpData, cbData); if (rc != ERROR_SUCCESS) { zend_error( E_WARNING, "Can't set registry value for value '%s': %s", value_name, win32_strerror(buffer, WIN32_STRERROR_BUFFER_LEN) ); RETURN_FALSE; } else { RETURN_TRUE; } } /* }}} */ /* {{{ proto mixed reg_get_value(mixed hKey, string value_name) */ PHP_FUNCTION(reg_get_value) { zval *zhKey; char *value_name = NULL; int value_len; HKEY hKey; DWORD value_type; BYTE *buf = NULL; DWORD buf_len; LONG rc; char buffer[WIN32_STRERROR_BUFFER_LEN]; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zs", &zhKey, &value_name, &value_len) == FAILURE) { return; } hKey = _registry_get_hkey(&zhKey TSRMLS_CC); rc = RegQueryValueEx(hKey, value_name, NULL, &value_type, NULL, &buf_len); if (rc != ERROR_SUCCESS) { RETURN_FALSE; } else { buf = (BYTE *)emalloc(buf_len); rc = RegQueryValueEx(hKey, value_name, NULL, &value_type, buf, &buf_len); if (rc != ERROR_SUCCESS) { zend_error( E_WARNING, "Can't get registry value '%s': %s", value_name, win32_strerror(buffer, WIN32_STRERROR_BUFFER_LEN) ); RETVAL_FALSE; } else { switch (value_type) { case REG_DWORD : RETVAL_LONG(*((DWORD *)buf)); break; case REG_EXPAND_SZ: case REG_SZ : RETVAL_STRINGL((char *)buf, buf_len-1, 1); break; default : RETVAL_FALSE; break; } } if (buf) efree(buf); } } /* }}} */ /* * Local variables: * tab-width: 4 * c-basic-offset: 4 * End: * vim600: noet sw=4 ts=4 fdm=marker * vim<600: noet sw=4 ts=4 */ Index: pecl/win32std/res.c +++ pecl/win32std/res.c /* +----------------------------------------------------------------------+ | PHP Version 4 | +----------------------------------------------------------------------+ | Copyright (c) 1997-2002 The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | | available at through the world-wide-web at | | http://www.php.net/license/3_0.txt. | | If you did not receive a copy of the PHP license and are unable to | | obtain it through the world-wide-web, please send a note to | | license@php.net so we can mail you a copy immediately. | +----------------------------------------------------------------------+ | Author: Eric COLINET <e.colinet@laposte.net> | +----------------------------------------------------------------------+ */ #include "php_win32std.h" #ifndef IS_INTRESOURCE #define IS_INTRESOURCE(_r) (((DWORD)(_r) >> 16) == 0) #endif /* static */ int le_res_resource; void _php_res_destruction_handler(zend_rsrc_list_entry *rsrc TSRMLS_DC) { HMODULE module = (HMODULE) rsrc->ptr; if( module ) FreeLibrary(module); } /* {{{ proto resource res_open( module_name ) Return a (PHP)resource that identify the (WIN)resource module handle */ PHP_FUNCTION(res_open) { HMODULE h_module= NULL; char *module= NULL; long module_len; char buffer[WIN32_STRERROR_BUFFER_LEN]; //res_resource * res_rc; if( zend_parse_parameters( ZEND_NUM_ARGS() TSRMLS_CC, "s", &module, &module_len ) == FAILURE ) RETURN_LONG(-1); // if module=="" module is the current executable if( !module_len ) h_module= NULL; else { h_module= LoadLibrary(module); if( !h_module ) { zend_error(E_WARNING, "res_open '%s' failed: %s", module, win32_strerror(buffer, WIN32_STRERROR_BUFFER_LEN)); RETURN_FALSE } } ZEND_REGISTER_RESOURCE( return_value, h_module, le_res_resource ); } /* }}} */ /* {{{ proto bool res_close( resouce module ) Close a module handle */ PHP_FUNCTION(res_close) { zval *res_rc; HMODULE h; if( zend_parse_parameters( ZEND_NUM_ARGS() TSRMLS_CC, "r", &res_rc ) == FAILURE ) RETURN_FALSE ZEND_FETCH_RESOURCE(h, HMODULE, &res_rc, -1, le_res_resource_name, le_res_resource); zend_list_delete(Z_RESVAL_P(res_rc)); RETURN_TRUE; } /* }}} */ /* {{{ proto res_get( resource module, string type, string name[, int lang] ) Get a resource. lang is experimental: 0 is neutral, 1 is user default, 2 is system default (see winnt.h LANG_* & SUBLANG_*). */ PHP_FUNCTION(res_get) { DWORD size; HGLOBAL rc; HMODULE h_module= NULL; HRSRC hr; char *module= NULL, *name= NULL, *type= NULL; long name_len, type_len; long lang= MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT); char buffer[WIN32_STRERROR_BUFFER_LEN]; zval *res_rc; if( zend_parse_parameters( ZEND_NUM_ARGS() TSRMLS_CC, "rss|l", &res_rc, &type, &type_len, &name, &name_len, &lang ) == FAILURE ) RETURN_NULL(); if( !name_len || !type_len ) { zend_error(E_WARNING, "res_get: name or type can't be empty"); RETURN_NULL(); } ZEND_FETCH_RESOURCE(h_module, HMODULE, &res_rc, -1, le_res_resource_name, le_res_resource); // Convert name and type to uppercase since lowercase don't work strupr(name); strupr(type); if( ZEND_NUM_ARGS()>3 ) hr= FindResourceEx( h_module, name, type, (WORD)lang ); else hr= FindResource( h_module, name, type ); if( hr==NULL ) { zend_error(E_WARNING, "res_get: find '%s/%s' failed: %s", type, name, win32_strerror(buffer, WIN32_STRERROR_BUFFER_LEN)); RETURN_NULL( ); } rc= LoadResource( h_module, hr ); if( rc==NULL ) { zend_error(E_WARNING, "res_get: load '%s/%s' failed: %s", type, name, win32_strerror(buffer, WIN32_STRERROR_BUFFER_LEN)); RETURN_NULL( ); } size= SizeofResource( h_module, hr ); RETVAL_STRINGL((char*)rc, size, 1); } /* }}} */ /* {{{ proto bool res_set( string file, string type, string name, string data[, int lang] ) Add or modify a resource in 'file' (dll or exe) lang is experimental: 0 is neutral, 1 is user default, 2 is system default (see winnt.h LANG_* & SUBLANG_*). */ PHP_FUNCTION(res_set) { HANDLE h_module; char *module, *type, *name, *data; int module_len, type_len, name_len, data_len; char buffer[WIN32_STRERROR_BUFFER_LEN]; long lang= MAKELANGID(LANG_NEUTRAL, SUBLANG_NEUTRAL); if( zend_parse_parameters( ZEND_NUM_ARGS() TSRMLS_CC, "ssss|l", &module, &module_len, &type, &type_len, &name, &name_len, &data, &data_len, &lang ) == FAILURE ) RETURN_FALSE; //zend_error( E_WARNING, "res_set modifie res://%s/%s/%s avec %d octets", // module, type, name, data_len ); if( !module_len || !type_len || !name_len ) { zend_error(E_WARNING, "res_set: module file, type or name can't be empty" ); RETURN_FALSE; } // Convert name and type to uppercase since lowercase don't work strupr(name); strupr(type); h_module= BeginUpdateResource( module, FALSE ); if( h_module==NULL ) { zend_error(E_WARNING, "res_set: error opening module: %s", win32_strerror(buffer, WIN32_STRERROR_BUFFER_LEN) ); RETURN_FALSE; } if( UpdateResource( h_module, type, name, (WORD)lang, data, data_len )==0 ) { zend_error(E_WARNING, "res_set: error updating module: %s", win32_strerror(buffer, WIN32_STRERROR_BUFFER_LEN) ); EndUpdateResource(h_module, TRUE); RETURN_FALSE; } EndUpdateResource(h_module, FALSE); RETURN_TRUE; } /* }}} */ long php_res_list_get_int_type( const char * string_type ) { if( !strcmp( string_type, "RT_CURSOR" ) ) return (long)RT_CURSOR; if( !strcmp( string_type, "RT_BITMAP" ) ) return (long)RT_BITMAP; if( !strcmp( string_type, "RT_ICON" ) ) return (long)RT_ICON; if( !strcmp( string_type, "RT_MENU" ) ) return (long)RT_MENU; if( !strcmp( string_type, "RT_DIALOG" ) ) return (long)RT_DIALOG; if( !strcmp( string_type, "RT_STRING" ) ) return (long)RT_STRING; if( !strcmp( string_type, "RT_FONTDIR" ) ) return (long)RT_FONTDIR; if( !strcmp( string_type, "RT_FONT" ) ) return (long)RT_FONT; if( !strcmp( string_type, "RT_ACCELERATOR" ) ) return (long)RT_ACCELERATOR; if( !strcmp( string_type, "RT_RCDATA" ) ) return (long)RT_RCDATA; if( !strcmp( string_type, "RT_MESSAGETABLE" ) ) return (long)RT_MESSAGETABLE; if( !strcmp( string_type, "RT_GROUP_CURSOR" ) ) return (long)RT_GROUP_CURSOR; if( !strcmp( string_type, "RT_GROUP_ICON" ) ) return (long)RT_GROUP_ICON; if( !strcmp( string_type, "RT_VERSION" ) ) return (long)RT_VERSION; if( !strcmp( string_type, "RT_DLGINCLUDE" ) ) return (long)RT_DLGINCLUDE; if( !strcmp( string_type, "RT_PLUGPLAY" ) ) return (long)RT_PLUGPLAY; if( !strcmp( string_type, "RT_VXD" ) ) return (long)RT_VXD; if( !strcmp( string_type, "RT_ANICURSOR" ) ) return (long)RT_ANICURSOR; if( !strcmp( string_type, "RT_ANIICON" ) ) return (long)RT_ANIICON; if( !strcmp( string_type, "RT_HTML" ) ) return (long)RT_HTML; //if( !strcmp( string_type, "RT_NOT_DOCUMENTED" ) ) return 241; return -1; } BOOL CALLBACK php_res_list_callback( HMODULE h_module, // module handle LPCTSTR lpszType, // pointer to resource type LPTSTR lpszName, // pointer to resource name LONG lParam // application-defined parameter ) { char buffer[8]; zval * array= (zval*) lParam; if( !IS_INTRESOURCE(lpszName) ) add_next_index_string(array, lpszName, 1); else { sprintf( buffer, "#%d", lpszName ); add_next_index_string(array, buffer, 1); } return TRUE; } /* {{{ proto array res_list( resource module, string type ) return the resource list for a given type */ PHP_FUNCTION(res_list) { char *module= NULL, *type= NULL; long type_len; HMODULE h_module= NULL; BOOL ret= FALSE; long int_type=-1; char buffer[WIN32_STRERROR_BUFFER_LEN]; zval * res_rc; if( zend_parse_parameters( ZEND_NUM_ARGS() TSRMLS_CC, "rs", &res_rc, &type, &type_len ) == FAILURE ) RETURN_FALSE; ZEND_FETCH_RESOURCE(h_module, HMODULE, &res_rc, -1, le_res_resource_name, le_res_resource); if( !type || !type[0] ) RETURN_FALSE; if( *type=='#' ) sscanf( type, "#%x", &int_type ); if( !strncmp( type, "RT_", 3 ) ) int_type= php_res_list_get_int_type( type ); if( !array_init( return_value ) ) { if( int_type==-1 ) ret= EnumResourceNames( h_module, type, php_res_list_callback, (LONG)return_value ); else ret= EnumResourceNames( h_module, MAKEINTRESOURCE(int_type), php_res_list_callback, (LONG)return_value ); if( !ret ) { if( GetLastError()!=1813 ) // No resource of this type { zend_error(E_WARNING, "res_list_type %s", win32_strerror(buffer, WIN32_STRERROR_BUFFER_LEN)); RETURN_FALSE; } else ret= TRUE; } } if( !ret ) RETURN_FALSE; } /* }}} */ BOOL CALLBACK php_res_list_type_callback( HMODULE hModule, // resource-module handle LPTSTR lpszType, // pointer to resource type LONG lParam // application-defined parameter ) { zval * array; char buffer[8]; array= (zval*) lParam; if( !IS_INTRESOURCE(lpszType) ) add_next_index_string(array, lpszType, 1); else { sprintf( buffer, "#%d", lpszType ); add_next_index_string(array, buffer, 1); } return TRUE; } BOOL CALLBACK php_res_list_type_string_callback( HMODULE hModule, // resource-module handle LPTSTR lpszType, // pointer to resource type LONG lParam // application-defined parameter ) { zval * array; char buffer[8]; array= (zval*) lParam; if( !IS_INTRESOURCE(lpszType) ) { add_next_index_string(array, lpszType, 1); return TRUE; } #define RES_LIST_TYPE_STRING(type) case type: add_next_index_string(array, #type, 1); break; switch( (DWORD)lpszType ) { RES_LIST_TYPE_STRING(RT_CURSOR) RES_LIST_TYPE_STRING(RT_BITMAP) RES_LIST_TYPE_STRING(RT_ICON) RES_LIST_TYPE_STRING(RT_MENU) RES_LIST_TYPE_STRING(RT_DIALOG) RES_LIST_TYPE_STRING(RT_STRING) RES_LIST_TYPE_STRING(RT_FONTDIR) RES_LIST_TYPE_STRING(RT_FONT) RES_LIST_TYPE_STRING(RT_ACCELERATOR) RES_LIST_TYPE_STRING(RT_RCDATA) RES_LIST_TYPE_STRING(RT_MESSAGETABLE) RES_LIST_TYPE_STRING(RT_GROUP_CURSOR) RES_LIST_TYPE_STRING(RT_GROUP_ICON) RES_LIST_TYPE_STRING(RT_VERSION) RES_LIST_TYPE_STRING(RT_DLGINCLUDE) RES_LIST_TYPE_STRING(RT_PLUGPLAY) RES_LIST_TYPE_STRING(RT_VXD) RES_LIST_TYPE_STRING(RT_ANICURSOR) RES_LIST_TYPE_STRING(RT_ANIICON) RES_LIST_TYPE_STRING(RT_HTML) default: sprintf( buffer, "#%d", lpszType ); add_next_index_string(array, buffer, 1); break; } #undef RES_LIST_TYPE_STRING return TRUE; } /* {{{ proto array res_list_type( resource module [, bool as_string=true] ) return the resource type list for a given module as_string specify if known type should be translated to string (but such string can't be used in res_get) */ PHP_FUNCTION(res_list_type) { char *module= NULL; HMODULE h_module= NULL; BOOL ret= FALSE; zend_bool as_string= 1; char buffer[WIN32_STRERROR_BUFFER_LEN]; zval *res_rc; if( zend_parse_parameters( ZEND_NUM_ARGS() TSRMLS_CC, "r|b", &res_rc, &as_string ) == FAILURE ) RETURN_FALSE; ZEND_FETCH_RESOURCE(h_module, HMODULE, &res_rc, -1, le_res_resource_name, le_res_resource); if( !array_init( return_value ) ) { if( !as_string ) ret= EnumResourceTypes( h_module, php_res_list_type_callback, (LONG)return_value ); else ret= EnumResourceTypes( h_module, php_res_list_type_string_callback, (LONG)return_value ); if( !ret ) { zend_error(E_WARNING, "res_list_type %d - %s", GetLastError(), win32_strerror(buffer, WIN32_STRERROR_BUFFER_LEN)); RETURN_FALSE; } } if( !ret ) RETURN_FALSE; } /* }}} */ Index: pecl/win32std/res_stream.c +++ pecl/win32std/res_stream.c /* +----------------------------------------------------------------------+ | PHP Version 4 | +----------------------------------------------------------------------+ | Copyright (c) 1997-2002 The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | | available at through the world-wide-web at | | http://www.php.net/license/3_0.txt. | | If you did not receive a copy of the PHP license and are unable to | | obtain it through the world-wide-web, please send a note to | | license@php.net so we can mail you a copy immediately. | +----------------------------------------------------------------------+ | Author: Eric COLINET <e.colinet@laposte.net> | +----------------------------------------------------------------------+ */ #include "php_win32std.h" typedef struct _res_stream_data{ HMODULE module; char *data; size_t size; size_t pos; } res_stream_data; static size_t php_res_read(php_stream *stream, char *buf, size_t count TSRMLS_DC) { res_stream_data *self = (res_stream_data *)stream->abstract; int read; read= count<self->size-self->pos?count:self->size-self->pos; memcpy(buf, self->data+self->pos, read); self->pos+= read; if( self->pos==self->size ) stream->eof= 1; return read; } static int php_res_seek(php_stream *stream, off_t offset, int whence, off_t *newoffs TSRMLS_DC) { res_stream_data *self = (res_stream_data *)stream->abstract; *newoffs= self->pos; assert(self!=NULL); switch( whence ) { case SEEK_SET: *newoffs= offset; break; case SEEK_CUR: *newoffs+= offset; break; case SEEK_END: *newoffs= self->size+offset; break; default: return -1; } if( *newoffs<0 || *newoffs>(off_t)self->size ) { *newoffs= self->pos; return -1; } self->pos= *newoffs; return 0; } static int php_res_close(php_stream *stream, int close_handle TSRMLS_DC) { res_stream_data *self = (res_stream_data *)stream->abstract; if( self->module ) FreeLibrary(self->module); efree(self); return 1; } /* Stream operation entry */ php_stream_ops php_res_stream_ops = { NULL,php_res_read, /* write, read */ php_res_close,NULL, /* close, flush */ "RES", php_res_seek, /* seek */ NULL, /* cast */ NULL, /* stat */ NULL /* set_option */ }; php_stream *php_res_stream_open(php_stream_wrapper *wrapper, char *path, char *mode, int options, char **opened_path, php_stream_context *context STREAMS_DC TSRMLS_DC); /* Wrapper operation entry */ static php_stream_wrapper_ops php_res_wrapper_ops = { php_res_stream_open, NULL, /* close */ NULL, /* stat */ NULL, /* stat_url */ NULL, /* opendir */ "RES" }; /* Wrapper entry */ php_stream_wrapper php_res_stream_wrapper = { &php_res_wrapper_ops, NULL, 0, /* is_url */ }; /* Can handle "res://c:\adir\another\file.dll/#145/#12" "res://c:\adir\another\file.dll/#145/#12/" "res://c:/adir/another/file.dll/#145/#12" "res://c:\adir\another\file.dll/TYPE/NAME" */ php_stream *php_res_stream_open(php_stream_wrapper *wrapper, char *path, char *mode, int options, char **opened_path, php_stream_context *context STREAMS_DC TSRMLS_DC) { res_stream_data *self; php_stream *stream = NULL; char *ptr, *type, *name, buffer[WIN32_STRERROR_BUFFER_LEN], *path_copy; int path_len; HRSRC hr; /* check: read only */ if( strchr(mode, '+') || strchr(mode, 'a') || strchr(mode, 'w')) { //if (options & REPORT_ERRORS) { zend_error(E_WARNING, "cannot open a res stream for writing"); //} return NULL; } self = emalloc(sizeof(res_stream_data)); memset(self, 0, sizeof(res_stream_data)); if( strncasecmp("res://", path, 6)==0 ) path+= 6; path_copy= estrdup(path); ptr= path_copy; // can't end with / path_len= strlen(path_copy); if( path_copy[path_len-1]=='/' ) path_copy[path_len]= 0; // search name ptr= path_copy; ptr= strrchr(ptr, '/'); if( !ptr ) { zend_error(E_WARNING, "bad res string" ); efree(self); efree(path_copy); return NULL; } name= ptr+1; *ptr= 0; // search type ptr= path_copy; ptr= strrchr(ptr, '/'); if( !ptr ) { zend_error(E_WARNING, "bad res string" ); efree(self); efree(path_copy); return NULL; } type= ptr+1; *ptr= 0; if( *path_copy ) { self->module= LoadLibrary(path_copy); if( !self->module ) { zend_error(E_WARNING, "open '%s' failed: %s", path_copy, win32_strerror(buffer, WIN32_STRERROR_BUFFER_LEN)); efree(self); efree(path_copy); return NULL; } } else self->module= NULL; // Current exe // Convert name and type to uppercase since lowercase don't work strupr(name); strupr(type); hr= FindResource( self->module, name, type ); if( hr==NULL ) { zend_error(E_WARNING, "find '%s/%s' failed: %s", type, name, win32_strerror(buffer, WIN32_STRERROR_BUFFER_LEN)); if( self->module ) FreeLibrary(self->module); efree(self); efree(path_copy); return NULL; } self->data= LoadResource( self->module, hr ); if( self->data==NULL ) { zend_error(E_WARNING, "load '%s/%s' failed: %s", type, name, win32_strerror(buffer, WIN32_STRERROR_BUFFER_LEN)); if( self->module ) FreeLibrary(self->module); efree(self); efree(path_copy); return NULL; } self->size= SizeofResource( self->module, hr ); efree(path_copy); // Allocate stream and return it stream = php_stream_alloc_rel(&php_res_stream_ops, self, 0, mode); if (stream) { stream->flags |= PHP_STREAM_FLAG_NO_BUFFER; //stream->flags |= PHP_STREAM_FLAG_NO_SEEK; return stream; } efree( self ); return NULL; } Index: pecl/win32std/win32std.c +++ pecl/win32std/win32std.c /* +----------------------------------------------------------------------+ | PHP Version 4 | +----------------------------------------------------------------------+ | Copyright (c) 1997-2002 The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | | available at through the world-wide-web at | | http://www.php.net/license/3_0.txt. | | If you did not receive a copy of the PHP license and are unable to | | obtain it through the world-wide-web, please send a note to | | license@php.net so we can mail you a copy immediately. | +----------------------------------------------------------------------+ | Author: Eric COLINET <e.colinet@laposte.net> | | Author: Frank M. Kromann <frank@kromann.info> | +----------------------------------------------------------------------+ */ #ifdef HAVE_CONFIG_H #include "config.h" #endif #include "php_win32std.h" #include "ext/standard/php_smart_str.h" /* Return the Win32 error string for the last called Win32 function */ const char * win32_strerror( char * buffer, long buffer_len) { if( !buffer || !buffer_len ) return NULL; *buffer= 0; FormatMessage( FORMAT_MESSAGE_FROM_SYSTEM, NULL, GetLastError(), 0, buffer, buffer_len, NULL); return buffer; } /**************************************************************************************/ /**************************************************************************************/ /****************************** Win32 Functions ***************************************/ /**************************************************************************************/ /**************************************************************************************/ /* {{{ proto bool win_shell_execute(string absolute_path[, string action, string args, string dir]) Execute a shell action on a file or directory Common actions: open, edit, explore, find, print, properties The shell act the same way when you double click on an icon (action=NULL) or when you choose a menu item on the right click button This way you can also execute programs that are totaly detached from the current one (useful with DirectX games for exemple). */ PHP_FUNCTION(win_shell_execute) { char *action= NULL, *file= NULL, *args=NULL, *dir=NULL; int action_len= 4, file_len=0, args_len=0, dir_len=0, ret; if( zend_parse_parameters( ZEND_NUM_ARGS() TSRMLS_CC, "s|sss", &file, &file_len, &action, &action_len, &args, &args_len, &dir, &dir_len ) == FAILURE ) RETURN_FALSE; ret= (int)ShellExecute( NULL, action, file, args, dir, SW_SHOW ); if( ret<=32 ) { switch( ret ) { case 0: zend_error(E_WARNING,"shell_execute failed - No more system memory"); break; #define SHELL_EXEC_ERROR(err) case err: zend_error( E_WARNING, "Unable to execute shell [%s] on '%s' (%s)", action, file, #err ); break; SHELL_EXEC_ERROR(ERROR_FILE_NOT_FOUND ); SHELL_EXEC_ERROR(ERROR_PATH_NOT_FOUND); SHELL_EXEC_ERROR(ERROR_BAD_FORMAT ); SHELL_EXEC_ERROR(SE_ERR_ACCESSDENIED ); SHELL_EXEC_ERROR(SE_ERR_ASSOCINCOMPLETE); SHELL_EXEC_ERROR(SE_ERR_DDEBUSY); SHELL_EXEC_ERROR(SE_ERR_DDEFAIL ); SHELL_EXEC_ERROR(SE_ERR_DDETIMEOUT ); SHELL_EXEC_ERROR(SE_ERR_DLLNOTFOUND ); SHELL_EXEC_ERROR(SE_ERR_NOASSOC ); SHELL_EXEC_ERROR(SE_ERR_OOM ); SHELL_EXEC_ERROR(SE_ERR_SHARE); #undef SHELL_EXEC_ERROR } RETURN_FALSE } RETURN_TRUE } /* }}} */ /* {{{ proto: play_wav( file[, loop]) file may be either NULL to stop playback or a file name to start it loop can be set to loop playback (default to false) module may be opened by res_open a file must represent the resource id (NOT IMPL) */ PHP_FUNCTION(win_play_wav) { char *file= NULL; int file_len=0; int ret; int default_flags; zend_bool loop= 0; if( zend_parse_parameters( ZEND_NUM_ARGS() TSRMLS_CC, "s|b", &file, &file_len, &loop ) == FAILURE ) RETURN_FALSE; if( !*file ) file= NULL; default_flags= SND_ASYNC | SND_NOSTOP | SND_NOWAIT; if( file==NULL ) default_flags= SND_PURGE; else if( loop ) default_flags|= SND_LOOP; ret= PlaySound( file, NULL, default_flags | SND_FILENAME ); if( ret ) RETURN_TRUE; RETURN_FALSE; } /* }}} */ /* {{{ proto bool win_beep(string type) plays the system sound used by default for pre-defined events: '*': System Asterisk '!': System Exclamation 'H': System Hand '?': System Question '1': System Default '0': Standard beep using the computer speaker */ PHP_FUNCTION(win_beep) { UINT beep_type; char * str= ""; int str_len= 0; if( zend_parse_parameters( ZEND_NUM_ARGS() TSRMLS_CC, "|s", &str, &str_len ) == FAILURE ) RETURN_FALSE; switch(*str) { case '*': // System Asterisk beep_type= MB_ICONASTERISK; break; case '!': // System Exclamation beep_type= MB_ICONEXCLAMATION; break; case 'H': // System Hand beep_type= MB_ICONHAND; break; case '?': // System Question beep_type= MB_ICONQUESTION; break; case '1': // System Default beep_type= MB_OK; break; default: case '0': // Standard beep using the computer speaker beep_type= 0xFFFFFFFF; zend_printf("Default\n"); break; } if( !MessageBeep( beep_type ) ) RETURN_FALSE; RETURN_TRUE; } /* }}} */ /* {{{ proto int win_create_link( file, link_file, args, descr, workingdir ) Create a MS link file (.lnk) Don't forget the .lnk at the end of link_file ! */ PHP_FUNCTION(win_create_link) { char *file, *link, *args=NULL, *descr=NULL, *workingdir=NULL; int file_len, link_len, args_len, descr_len, workingdir_len; if( zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss|sss", &file, &file_len, &link, &link_len, &args, &args_len, &descr, &descr_len, &workingdir, &workingdir_len) == FAILURE ) { return; } if( !php_create_link(file, link, args, descr, workingdir) ) { RETURN_FALSE; } RETURN_TRUE; } /* }}} */ /* {{{ proto int win_message_box( text[, type, caption] ) Prompt a typical Win32 message box. Use the Messages Box Constants to modify the appearance of the message box */ PHP_FUNCTION(win_message_box) { char *text, *caption= "PHP"; int text_len, caption_len, type=MB_OK; if( zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|ls", &text, &text_len, &type, &caption, &caption_len) == FAILURE ) { RETURN_FALSE; } RETURN_LONG(MessageBox(NULL, text, caption, type|MB_TASKMODAL)); } /* }}} */ /* {{{ proto int win_browse_folder( [string dir, string caption=""] ) Prompt a "browse for folder" message box */ PHP_FUNCTION(win_browse_folder) { char *dir=NULL, *caption=NULL, system_dir[MAX_PATH+1]= ""; int dir_len, caption_len; if( zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|ss", &dir, &dir_len, &caption, &caption_len) == FAILURE ) { return; } if( dir ) { strncpy( system_dir, dir, MAX_PATH ); system_dir[MAX_PATH]= 0; } if( !php_browse_for_folder(NULL, caption, system_dir) ) { RETURN_NULL() } RETVAL_STRING( system_dir, 1 ); } /* }}} */ /* {{{ proto string win_browse_file( [open, path, filename, ext, filter] ) open or save dialog box, starting path, default filename, default extension, filter in MS format Filter exemple: "HTML File\0*.htm;*.html\0INI file\0*.ini\0All files\0*.*\0\0" or: array( "HTML File" => "*.htm;*.html", "INI File" => "*.ini", "All file" => "*.*" ) */ PHP_FUNCTION(win_browse_file) { char *ext= NULL, *path= NULL, *file= NULL, *key; int open=1, ext_len, path_len, file_len, free_filter= 0, key_len, not_string; zval *zfilter= NULL, **entry; char fileBuffer[MAX_PATH]= ""; OPENFILENAME ofn; BOOL res; HashPosition pos; smart_str smart_filter= {0}; if( zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|lsssz", &open, &path, &path_len, &file, &file_len, &ext, &ext_len, &zfilter) == FAILURE ) RETURN_NULL(); if( file ) strcpy(fileBuffer, file ); memset(&ofn, 0, sizeof(OPENFILENAME)); ofn.lStructSize= sizeof(OPENFILENAME); ofn.hwndOwner= NULL; ofn.lpstrFilter= NULL; ofn.lpstrFile= fileBuffer; ofn.nMaxFile= MAX_PATH; //ofn.lpstrFileTitle //ofn.nMaxFileTitle ofn.lpstrInitialDir= path; //ofn.lpstrTitle= "Choose file"; ofn.lpstrDefExt= ext; ofn.Flags= OFN_CREATEPROMPT|OFN_NOCHANGEDIR|OFN_OVERWRITEPROMPT|OFN_PATHMUSTEXIST|OFN_HIDEREADONLY; //OFN_FILEMUSTEXIST /* Filter */ free_filter= 0; if( zfilter && Z_TYPE_P(zfilter)==IS_ARRAY ) { not_string= 0; zend_hash_internal_pointer_reset_ex(Z_ARRVAL_P(zfilter), &pos); while (zend_hash_get_current_data_ex(Z_ARRVAL_P(zfilter), (void **)&entry, &pos) == SUCCESS) { if( zend_hash_get_current_key_ex(Z_ARRVAL_P(zfilter), &key, &key_len, &key_len, 0, &pos)!=HASH_KEY_IS_STRING ) { not_string= 1; break; } if( Z_TYPE_PP(entry)!=IS_STRING ) { /*not_string= 1;*/ zend_error( E_WARNING, "win_browse_file: filter key '%s' must have a string value", key ); zend_hash_move_forward_ex(Z_ARRVAL_P(zfilter), &pos); continue; } smart_str_appends( &smart_filter, key ); smart_str_appendc( &smart_filter, '\0' ); smart_str_appends( &smart_filter, Z_STRVAL_PP(entry) ); smart_str_appendc( &smart_filter, '\0' ); zend_hash_move_forward_ex(Z_ARRVAL_P(zfilter), &pos); } if(not_string ) { zend_error( E_WARNING, "win_browse_file: filter must be an associative array" ); smart_str_free(&smart_filter); } smart_str_appendc( &smart_filter, '\0' ); ofn.lpstrFilter= smart_filter.c; free_filter= 1; } else if( zfilter && Z_TYPE_P(zfilter)==IS_STRING ) { ofn.lpstrFilter= Z_STRVAL_P(zfilter); } else if( zfilter ) { zend_error( E_WARNING, "win_browse_file: the filter parameter must be an array" ); } if( open ) res= GetOpenFileName(&ofn); else res= GetSaveFileName(&ofn); if( free_filter ) smart_str_free(&smart_filter); if( !res ) RETURN_NULL() else RETVAL_STRING(fileBuffer,1) } /* }}} */ /*******************************************************************/ /*******************************************************************/ /************************** PHP EXT STUFF **************************/ /*******************************************************************/ /*******************************************************************/ /* If you declare any globals in php_win32std.h uncomment this: ZEND_DECLARE_MODULE_GLOBALS(win32std) */ /* True global resources - no need for thread safety here */ //static int le_win32std; /* {{{ win32std_functions[] * * Every user visible function must have an entry in win32std_functions[]. */ function_entry win32std_functions[] = { /* Res */ PHP_FE(res_get, NULL) PHP_FE(res_list, NULL) PHP_FE(res_list_type, NULL) PHP_FE(res_open, NULL) PHP_FE(res_close, NULL) PHP_FE(res_set, NULL) /* Win32 */ PHP_FE(win_shell_execute, NULL) PHP_FE(win_play_wav, NULL) PHP_FE(win_beep, NULL) PHP_FE(win_message_box, NULL) PHP_FE(win_create_link, NULL) PHP_FE(win_browse_folder, NULL) PHP_FE(win_browse_file, NULL) /* Registry */ PHP_FE(reg_close_key, NULL) PHP_FE(reg_create_key, NULL) PHP_FE(reg_enum_key, NULL) PHP_FE(reg_enum_value, NULL) PHP_FE(reg_open_key, NULL) PHP_FE(reg_set_value, NULL) PHP_FE(reg_get_value, NULL) {NULL, NULL, NULL} /* Must be the last line in win32std_functions[] */ }; /* }}} */ #if ZEND_MODULE_API_NO < 20010901 # error Module made for PHP 4.1.x #endif /* {{{ win32std_module_entry */ zend_module_entry win32std_module_entry = { #if ZEND_MODULE_API_NO >= 20010901 STANDARD_MODULE_HEADER, #endif "win32std", win32std_functions, ZEND_MINIT(win32std), ZEND_MSHUTDOWN(win32std), ZEND_RINIT(win32std), /* Replace with NULL if there's nothing to do at request start */ ZEND_RSHUTDOWN(win32std), /* Replace with NULL if there's nothing to do at request end */ #if ZEND_MODULE_API_NO >= 20010901 ZEND_MINFO(win32std), #endif "0.1", /* Replace with version number for your extension */ STANDARD_MODULE_PROPERTIES }; /* }}} */ #ifdef COMPILE_DL_WIN32STD ZEND_GET_MODULE(win32std) #endif /* {{{ PHP_INI */ /* Remove comments and fill if you need to have entries in php.ini PHP_INI_BEGIN() STD_PHP_INI_ENTRY("win32std.value", "42", PHP_INI_ALL, OnUpdateInt, global_value, zend_win32std_globals, win32std_globals) STD_PHP_INI_ENTRY("win32std.string", "foobar", PHP_INI_ALL, OnUpdateString, global_string, zend_win32std_globals, win32std_globals) PHP_INI_END() */ /* }}} */ /* {{{ php_win32std_init_globals */ /* Uncomment this function if you have INI entries static void php_win32std_init_globals(zend_win32std_globals *win32std_globals) { win32std_globals->value = 0; win32std_globals->string = NULL; } */ /* }}} */ /* {{{ PHP_MINIT_FUNCTION */ ZEND_MINIT_FUNCTION(win32std) { /* If you have INI entries, uncomment these lines ZEND_INIT_MODULE_GLOBALS(win32std, php_win32std_init_globals, NULL); REGISTER_INI_ENTRIES(); */ /** * Resources **/ le_res_resource = zend_register_list_destructors_ex(_php_res_destruction_handler, NULL, le_res_resource_name, module_number); php_register_url_stream_wrapper("res", &php_res_stream_wrapper TSRMLS_CC); /* Resource type constants */ REGISTER_STRING_CONSTANT("RT_CURSOR", ("#1"), CONST_CS|CONST_PERSISTENT); REGISTER_STRING_CONSTANT("RT_BITMAP", ("#2"), CONST_CS|CONST_PERSISTENT); REGISTER_STRING_CONSTANT("RT_ICON", ("#3"), CONST_CS|CONST_PERSISTENT); REGISTER_STRING_CONSTANT("RT_MENU", ("#4"), CONST_CS|CONST_PERSISTENT); REGISTER_STRING_CONSTANT("RT_DIALOG", ("#5"), CONST_CS|CONST_PERSISTENT); REGISTER_STRING_CONSTANT("RT_STRING", ("#6"), CONST_CS|CONST_PERSISTENT); REGISTER_STRING_CONSTANT("RT_FONTDIR", ("#7"), CONST_CS|CONST_PERSISTENT); REGISTER_STRING_CONSTANT("RT_FONT", ("#8"), CONST_CS|CONST_PERSISTENT); REGISTER_STRING_CONSTANT("RT_ACCELERATOR", ("#9"), CONST_CS|CONST_PERSISTENT); REGISTER_STRING_CONSTANT("RT_RCDATA", ("#10"), CONST_CS|CONST_PERSISTENT); REGISTER_STRING_CONSTANT("RT_MESSAGETABLE", ("#11"), CONST_CS|CONST_PERSISTENT); REGISTER_STRING_CONSTANT("RT_GROUP_CURSOR", ("#12"), CONST_CS|CONST_PERSISTENT); REGISTER_STRING_CONSTANT("RT_GROUP_ICON", ("#14"), CONST_CS|CONST_PERSISTENT); REGISTER_STRING_CONSTANT("RT_VERSION", ("#16"), CONST_CS|CONST_PERSISTENT); REGISTER_STRING_CONSTANT("RT_DLGINCLUDE", ("#17"), CONST_CS|CONST_PERSISTENT); REGISTER_STRING_CONSTANT("RT_PLUGPLAY", ("#19"), CONST_CS|CONST_PERSISTENT); REGISTER_STRING_CONSTANT("RT_VXD", ("#20"), CONST_CS|CONST_PERSISTENT); REGISTER_STRING_CONSTANT("RT_ANICURSOR", ("#21"), CONST_CS|CONST_PERSISTENT); REGISTER_STRING_CONSTANT("RT_ANIICON", ("#22"), CONST_CS|CONST_PERSISTENT); REGISTER_STRING_CONSTANT("RT_HTML", ("#23"), CONST_CS|CONST_PERSISTENT); REGISTER_STRING_CONSTANT("RT_NOT_DOCUMENTED", ("#241"), CONST_CS|CONST_PERSISTENT); /** * Messages box **/ /* Message box type constants */ REGISTER_LONG_CONSTANT("MB_OK", MB_OK, CONST_CS|CONST_PERSISTENT); REGISTER_LONG_CONSTANT("MB_OKCANCEL", MB_OKCANCEL, CONST_CS|CONST_PERSISTENT); REGISTER_LONG_CONSTANT("MB_RETRYCANCEL", MB_RETRYCANCEL, CONST_CS|CONST_PERSISTENT); REGISTER_LONG_CONSTANT("MB_YESNO", MB_YESNO, CONST_CS|CONST_PERSISTENT); REGISTER_LONG_CONSTANT("MB_YESNOCANCEL", MB_YESNOCANCEL, CONST_CS|CONST_PERSISTENT); /* Message box icon constants */ REGISTER_LONG_CONSTANT("MB_ICONEXCLAMATION", MB_ICONEXCLAMATION, CONST_CS|CONST_PERSISTENT); REGISTER_LONG_CONSTANT("MB_ICONWARNING", MB_ICONWARNING, CONST_CS|CONST_PERSISTENT); REGISTER_LONG_CONSTANT("MB_ICONINFORMATION", MB_ICONINFORMATION, CONST_CS|CONST_PERSISTENT); REGISTER_LONG_CONSTANT("MB_ICONASTERISK", MB_ICONASTERISK, CONST_CS|CONST_PERSISTENT); REGISTER_LONG_CONSTANT("MB_ICONQUESTION", MB_ICONQUESTION, CONST_CS|CONST_PERSISTENT); REGISTER_LONG_CONSTANT("MB_ICONSTOP", MB_ICONSTOP, CONST_CS|CONST_PERSISTENT); REGISTER_LONG_CONSTANT("MB_ICONERROR", MB_ICONERROR, CONST_CS|CONST_PERSISTENT); REGISTER_LONG_CONSTANT("MB_ICONHAND", MB_ICONHAND, CONST_CS|CONST_PERSISTENT); /* Message box default button constants */ REGISTER_LONG_CONSTANT("MB_DEFBUTTON1", MB_DEFBUTTON1, CONST_CS|CONST_PERSISTENT); REGISTER_LONG_CONSTANT("MB_DEFBUTTON2", MB_DEFBUTTON2, CONST_CS|CONST_PERSISTENT); REGISTER_LONG_CONSTANT("MB_DEFBUTTON3", MB_DEFBUTTON3, CONST_CS|CONST_PERSISTENT); REGISTER_LONG_CONSTANT("MB_DEFBUTTON4", MB_DEFBUTTON4, CONST_CS|CONST_PERSISTENT); /* Message box return constants */ REGISTER_LONG_CONSTANT("MB_IDABORT", IDABORT, CONST_CS|CONST_PERSISTENT); REGISTER_LONG_CONSTANT("MB_IDCANCEL", IDCANCEL, CONST_CS|CONST_PERSISTENT); REGISTER_LONG_CONSTANT("MB_IDNO", IDNO, CONST_CS|CONST_PERSISTENT); REGISTER_LONG_CONSTANT("MB_IDOK", IDOK, CONST_CS|CONST_PERSISTENT); REGISTER_LONG_CONSTANT("MB_IDYES", IDYES, CONST_CS|CONST_PERSISTENT); // REGISTER_LONG_CONSTANT("MB_IDCONTINUE", IDCONTINUE, CONST_CS|CONST_PERSISTENT); REGISTER_LONG_CONSTANT("MB_IDIGNORE", IDIGNORE, CONST_CS|CONST_PERSISTENT); REGISTER_LONG_CONSTANT("MB_IDRETRY", IDRETRY, CONST_CS|CONST_PERSISTENT); // REGISTER_LONG_CONSTANT("MB_IDTRYAGAIN", IDTRYAGAIN, CONST_CS|CONST_PERSISTENT); /** * Registry **/ le_key = zend_register_list_destructors_ex(php_hkey_close, NULL, le_key_resource_name, module_number); /* Registry main key constants */ REGISTER_LONG_CONSTANT("HKEY_CLASSES_ROOT", 0, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("HKEY_CURRENT_CONFIG", 1, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("HKEY_CURRENT_USER", 2, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("HKEY_LOCAL_MACHINE", 3, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("HKEY_USERS", 4, CONST_CS | CONST_PERSISTENT); /* Registry access type */ REGISTER_LONG_CONSTANT("KEY_ALL_ACCESS", KEY_ALL_ACCESS, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("KEY_WRITE", KEY_WRITE, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("KEY_READ", KEY_READ, CONST_CS | CONST_PERSISTENT); /* Registry value type */ REGISTER_LONG_CONSTANT("REG_BINARY", REG_BINARY, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("REG_DWORD", REG_DWORD, CONST_CS | CONST_PERSISTENT); // REGISTER_LONG_CONSTANT("REG_DWORD_LITTLE_ENDIAN", REG_DWORD_LITTLE_ENDIAN, CONST_CS | CONST_PERSISTENT); // REGISTER_LONG_CONSTANT("REG_DWORD_BIG_ENDIAN", REG_DWORD_BIG_ENDIAN, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("REG_EXPAND_SZ", REG_EXPAND_SZ, CONST_CS | CONST_PERSISTENT); // REGISTER_LONG_CONSTANT("REG_LINK", REG_LINK, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("REG_MULTI_SZ", REG_MULTI_SZ, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("REG_NONE", REG_NONE, CONST_CS | CONST_PERSISTENT); // REGISTER_LONG_CONSTANT("REG_RESOURCE_LIST", REG_RESOURCE_LIST, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("REG_SZ", REG_SZ, CONST_CS | CONST_PERSISTENT); return SUCCESS; } /* }}} */ /* {{{ PHP_MSHUTDOWN_FUNCTION */ ZEND_MSHUTDOWN_FUNCTION(win32std) { /* uncomment this line if you have INI entries UNREGISTER_INI_ENTRIES(); */ return SUCCESS; } /* }}} */ /* Remove if there's nothing to do at request start */ /* {{{ PHP_RINIT_FUNCTION */ ZEND_RINIT_FUNCTION(win32std) { return SUCCESS; } /* }}} */ /* Remove if there's nothing to do at request end */ /* {{{ PHP_RSHUTDOWN_FUNCTION */ ZEND_RSHUTDOWN_FUNCTION(win32std) { return SUCCESS; } /* }}} */ /* {{{ PHP_MINFO_FUNCTION */ ZEND_MINFO_FUNCTION(win32std) { php_info_print_table_start(); php_info_print_table_header(2, "win32std", "enabled"); php_info_print_table_row(2, "resource support", "enabled"); php_info_print_table_row(2, "message box support", "enabled"); php_info_print_table_row(2, "registry support", "enabled"); php_info_print_table_end(); /* Remove comments if you have entries in php.ini DISPLAY_INI_ENTRIES(); */ } /* }}} */ /* Remove the following function when you have succesfully modified config.m4 so that your module can be compiled into PHP, it exists only for testing purposes. */ /* Every user-visible function in PHP should document itself in the source */ /* {{{ proto string confirm_win32std_compiled(string arg) Return a string to confirm that the module is compiled in */ PHP_FUNCTION(confirm_win32std_compiled) { char *arg = NULL; int arg_len, len; char string[256]; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &arg, &arg_len) == FAILURE) { return; } len = sprintf(string, "Congratulations! You have successfully modified ext/%.78s/config.m4. Module %.78s is now compiled into PHP.", "win32std", arg); RETURN_STRINGL(string, len, 1); } /* }}} */ /* BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved) { switch (fdwReason) { case DLL_PROCESS_ATTACH: break; case DLL_THREAD_ATTACH: break; case DLL_THREAD_DETACH: break; case DLL_PROCESS_DETACH: break; } return TRUE; }*/ //_DEBUG,__WIN32__,ZEND_DEBUG=1,_WINDOWS,_USRDLL,ZTS,ZEND_WIN32,PHP_WIN32,WIN32,_MBCS,USE_WSAPI //_DEBUG,__WIN32__,USE_TLS,WIN32,_MBCS,ZEND_DEBUG=1,NDEBUG,_WINDOWS,_USRDLL,SBEE_EXPORTS,COMPILE_DL_SBEE,ZTS=1,ZEND_WIN32,PHP_WIN32,HAVE_SBEE=1 /* * Local variables: * tab-width: 4 * c-basic-offset: 4 * End: * vim600: sw=4 ts=4 tw=78 fdm=marker * vim<600: sw=4 ts=4 tw=78 */ Index: pecl/win32std/win32std.dsp +++ pecl/win32std/win32std.dsp # Microsoft Developer Studio Project File - Name="win32std" - Package Owner=<4> # Microsoft Developer Studio Generated Build File, Format Version 6.00 # ** DO NOT EDIT ** # TARGTYPE "Win32 (x86) Dynamic-Link Library" 0x0102 CFG=win32std - Win32 Release !MESSAGE This is not a valid makefile. To build this project using NMAKE, !MESSAGE use the Export Makefile command and run !MESSAGE !MESSAGE NMAKE /f "win32std.mak". !MESSAGE !MESSAGE You can specify a configuration when running NMAKE !MESSAGE by defining the macro CFG on the command line. For example: !MESSAGE !MESSAGE NMAKE /f "win32std.mak" CFG="win32std - Win32 Release" !MESSAGE !MESSAGE Possible choices for configuration are: !MESSAGE !MESSAGE "win32std - Win32 Release" (based on "Win32 (x86) Dynamic-Link Library") !MESSAGE "win32std - Win32 Debug" (based on "Win32 (x86) Dynamic-Link Library") !MESSAGE # Begin Project # PROP AllowPerConfigDependencies 0 # PROP Scc_ProjName "" # PROP Scc_LocalPath "" CPP=cl.exe MTL=midl.exe RSC=rc.exe !IF "$(CFG)" == "win32std - Win32 Release" # PROP BASE Use_MFC 0 # PROP BASE Use_Debug_Libraries 0 # PROP BASE Output_Dir "Release" # PROP BASE Intermediate_Dir "Release" # PROP BASE Target_Dir "" # PROP Use_MFC 0 # PROP Use_Debug_Libraries 0 # PROP Output_Dir "Release" # PROP Intermediate_Dir "Release" # PROP Ignore_Export_Lib 0 # PROP Target_Dir "" # ADD BASE CPP /nologo /MT /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "PHP_WIN32STD_EXPORTS" /YX /FD /c # ADD CPP /nologo /MD /W3 /GX /O2 /I "..\.." /I "..\..\main" /I "..\..\Zend" /I "..\..\TSRM" /D ZTS=1 /D "NDEBUG" /D ZEND_DEBUG=0 /D "PHP_WIN32" /D "ZEND_WIN32" /D "WIN32" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "COMPILE_DL_WIN32STD" /D HAVE_WIN32STD=1 /YX /FD /c # ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /win32 # ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32 # ADD BASE RSC /l 0x40c /d "NDEBUG" # ADD RSC /l 0x40c /d "NDEBUG" BSC32=bscmake.exe # ADD BASE BSC32 /nologo # ADD BSC32 /nologo LINK32=link.exe # ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /machine:I386 # ADD LINK32 php4ts.lib winmm.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /machine:I386 /out:"Release/php_win32std.dll" !ELSEIF "$(CFG)" == "win32std - Win32 Debug" # PROP BASE Use_MFC 0 # PROP BASE Use_Debug_Libraries 1 # PROP BASE Output_Dir "Debug" # PROP BASE Intermediate_Dir "Debug" # PROP BASE Target_Dir "" # PROP Use_MFC 0 # PROP Use_Debug_Libraries 1 # PROP Output_Dir "Debug" # PROP Intermediate_Dir "Debug" # PROP Ignore_Export_Lib 0 # PROP Target_Dir "" # ADD BASE CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "PHP_WIN32STD_EXPORTS" /YX /FD /GZ /c # ADD CPP /nologo /MDd /W3 /Gm /GX /ZI /Od /I "..\.." /I "..\..\main" /I "..\..\Zend" /I "..\..\TSRM" /D ZTS=1 /D "_DEBUG" /D ZEND_DEBUG=1 /D "PHP_WIN32" /D "ZEND_WIN32" /D "WIN32" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "COMPILE_DL_WIN32STD" /D HAVE_WIN32STD=1 /YX /FD /GZ /c # ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /win32 # ADD MTL /nologo /D "_DEBUG" /mktyplib203 /win32 # ADD BASE RSC /l 0x40c /d "_DEBUG" # ADD RSC /l 0x40c /d "_DEBUG" BSC32=bscmake.exe # ADD BASE BSC32 /nologo # ADD BSC32 /nologo LINK32=link.exe # ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /debug /machine:I386 /pdbtype:sept # ADD LINK32 php4ts_debug.lib winmm.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /debug /machine:I386 /out:"Debug/php_win32std.dll" /pdbtype:sept !ENDIF # Begin Target # Name "win32std - Win32 Release" # Name "win32std - Win32 Debug" # Begin Group "Source Files" # PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat" # Begin Source File SOURCE=.\cpp_wrappers.cpp # End Source File # Begin Source File SOURCE=.\registry.c # End Source File # Begin Source File SOURCE=.\res.c # End Source File # Begin Source File SOURCE=.\res_stream.c # End Source File # Begin Source File SOURCE=.\win32std.c # End Source File # End Group # Begin Group "Header Files" # PROP Default_Filter "h;hpp;hxx;hm;inl" # Begin Source File SOURCE=.\php_win32std.h # End Source File # End Group # Begin Group "Resource Files" # PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe" # End Group # End Target # End Project Index: pecl/win32std/examples/win32std.php +++ pecl/win32std/examples/win32std.php <? function err( $txt ) { echo "ERROR: ".$txt."\n"; exit; } /* Message box exemple */ if( win_message_box( "Hey !\n\nThis is win32std extension test\n\nAre you realy sure you want to start it ?", MB_YESNO|MB_ICONQUESTION|MB_DEFBUTTON2 )!=MB_IDYES ) return FALSE; /* Browse exemple */ $filter= array( "HTML File" => "*.htm;*.html", "INI File" => "*.ini", "All file" => "*.*" ); echo win_browse_file( 1, NULL, 'a_file', 'ext', $filter )."\n"; echo win_browse_folder(NULL, "Choose a dir")."\n"; /* Shell execute exemple */ win_shell_execute( 'c:\\', "find" ); /* beep exemple */ if( !win_beep('*') ) echo "Unable to beep !\n"; else echo "Bip !\n"; /* Sound exemple */ if( !win_play_wav( "%WINDIR%\Media\ringin.wav", 1 ) ) echo "Unable to play sound !\n"; else { echo "Playing sound !\n"; sleep(1); if( !win_play_wav( NULL ) ) echo "Unable to stop playing sound !\n"; else echo "Play stopped !\n"; } /* Reg exemple */ $strMainKey= 'Control Panel'; $mainKey= reg_open_key( HKEY_CURRENT_USER, $strMainKey ); if( !$mainKey ) err( "Can't open '$strMainKey' !" ); echo "'$strMainKey' Key opened\n\nKeys:\n"; print_r( reg_enum_key($mainKey) ); for( $i= 0; $key= reg_enum_key($mainKey, $i); $i++ ) { echo "\t$key\n"; } echo "\nValues:\n"; print_r( reg_enum_value($mainKey) ); for( $i= 0; $value= reg_enum_value($mainKey, $i); $i++ ) { echo "\t$value=".reg_get_value($mainKey, $value)."\n"; } reg_close_key($mainKey); /* Res exemple */ $dll_file= 'test_resource.dll'; $file= realpath($dll_file); if( empty($file) ) err( 'The res exemple need a dll file ! ('.$dll_file.' is missing)' ); res_set( $file, 'A_TYPE', 'A_RC_NAME', 'The time: '.date('d-m-Y h:i') ); echo "Res Stream read: ".file_get_contents('res://'.$file.'/A_TYPE/A_RC_NAME')."\n\n"; $h= res_open( $file ); if( !$h ) err( "can't open ".$file ); echo "Res list of '$file': \n"; $list= res_list_type($h, true); if( $list===FALSE ) err( "Can't list type" ); for( $i= 0; $i<count($list); $i++ ) { echo $list[$i]."\n"; $res= res_list($h, $list[$i]); for( $j= 0; $j<count($res); $j++ ) { echo "\t".$res[$j]."\n"; } } echo "Res get: ".res_get( $h, 'A_TYPE', 'A_RC_NAME' )."\n\n"; res_close( $h ); ?>
« previous php.pecl.cvs (#636) next »