cvs: php4 /ext/com COM.c

From: Date: Tue, 02 Jan 2001 23:08:19 +0000
Subject: cvs: php4 /ext/com COM.c
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-3333@lists.php.net to get a copy of this message
zeev Tue Jan 2 15:08:19 2001 EDT Modified files: /php4/ext/com COM.c Log: Import COM patch from Harald Radi <h.radi@nme.at> The new code should allow for better international support. Index: php4/ext/com/COM.c diff -u php4/ext/com/COM.c:1.42 php4/ext/com/COM.c:1.43 --- php4/ext/com/COM.c:1.42 Fri Dec 22 04:57:05 2000 +++ php4/ext/com/COM.c Tue Jan 2 15:08:19 2001 @@ -33,10 +33,23 @@ * Zeev */ +/* + * 28.12.2000 + * unicode conversion fixed by Harald Radi <h.radi@nme.at> + * + * now all these strange '?'s should be disapeared + */ + #ifdef PHP_WIN32 #define _WIN32_DCOM +#ifdef CP_THREAD_ACP +#define PHP_COM_CODEPAGE CP_THREAD_ACP +#else +#define PHP_COM_CODEPAGE CP_ACP +#endif + #include "php.h" #include "php_COM.h" #include "zend_compile.h" @@ -46,6 +59,7 @@ #include "objbase.h" #include "olestd.h" #include <ctype.h> +#include <windows.h> static int le_idispatch; @@ -104,13 +118,32 @@ static OLECHAR *php_char_to_OLECHAR(char *C_str, uint strlen) { - OLECHAR *unicode_str = (OLECHAR *) emalloc(sizeof(OLECHAR)*(strlen+1)); - OLECHAR *unicode_ptr = unicode_str; + OLECHAR *unicode_str; + + //request needed buffersize + uint reqSize = MultiByteToWideChar(PHP_COM_CODEPAGE, MB_PRECOMPOSED | MB_ERR_INVALID_CHARS, C_str, -1, NULL, 0); - while (*C_str) { - *unicode_ptr++ = (unsigned short) *C_str++; + if(reqSize) + { + unicode_str = (OLECHAR *) emalloc(sizeof(OLECHAR) * reqSize); + + //convert string + MultiByteToWideChar(PHP_COM_CODEPAGE, MB_PRECOMPOSED | MB_ERR_INVALID_CHARS, C_str, -1, unicode_str, reqSize); + } + else + { + unicode_str = (OLECHAR *) emalloc(sizeof(OLECHAR)); + *unicode_str = 0; + + switch(GetLastError()) + { + case ERROR_NO_UNICODE_TRANSLATION: + php_error(E_WARNING,"No unicode translation available for the specified string"); + break; + default: + php_error(E_WARNING,"Error in php_char_to_OLECHAR()"); + } } - *unicode_ptr = 0; return unicode_str; } @@ -118,17 +151,29 @@ char *php_OLECHAR_to_char(OLECHAR *unicode_str, uint *out_length, int persistent) { - uint length = OLESTRLEN(unicode_str); - char *C_str = (char *) pemalloc(length+1, persistent), *p = C_str; + char *C_str; + uint length = 0; + + //request needed buffersize + uint reqSize = WideCharToMultiByte(PHP_COM_CODEPAGE, WC_COMPOSITECHECK, unicode_str, -1, NULL, 0, NULL, NULL); + + if(reqSize) + { + C_str = (char *) pemalloc(sizeof(char) * reqSize, persistent); - while (*unicode_str) { - *p++ = (char) *unicode_str++; + //convert string + length = WideCharToMultiByte(PHP_COM_CODEPAGE, WC_COMPOSITECHECK, unicode_str, -1, C_str, reqSize, NULL, NULL) - 1; } - *p = 0; + else + { + C_str = (char *) pemalloc(sizeof(char), persistent); + *C_str = 0; + + php_error(E_WARNING,"Error in php_OLECHAR_to_char()"); + } - if (out_length) { + if(out_length) *out_length = length; - } return C_str; }

« previous php.cvs (#3333) next »