Back to index

php5  5.3.10
Functions
com_olechar.c File Reference
#include "php.h"
#include "php_ini.h"
#include "ext/standard/info.h"
#include "php_com_dotnet.h"
#include "php_com_dotnet_internal.h"

Go to the source code of this file.

Functions

PHPAPI OLECHAR * php_com_string_to_olestring (char *string, uint string_len, int codepage TSRMLS_DC)
PHPAPI char * php_com_olestring_to_string (OLECHAR *olestring, uint *string_len, int codepage TSRMLS_DC)

Function Documentation

PHPAPI char* php_com_olestring_to_string ( OLECHAR *  olestring,
uint string_len,
int codepage  TSRMLS_DC 
)

Definition at line 68 of file com_olechar.c.

{
       char *string;
       uint length = 0;
       BOOL ok;

       length = WideCharToMultiByte(codepage, 0, olestring, -1, NULL, 0, NULL, NULL);

       if (length) {
              string = (char*)safe_emalloc(length, sizeof(char), 0);
              length = WideCharToMultiByte(codepage, 0, olestring, -1, string, length, NULL, NULL);
              ok = length > 0;
       } else {
              string = (char*)emalloc(sizeof(char));
              *string = '\0';
              ok = FALSE;
              length = 0;
       }

       if (!ok) {
              char *msg = php_win_err(GetLastError());

              php_error_docref(NULL TSRMLS_CC, E_WARNING,
                     "Could not convert string from unicode: `%s'", msg);

              LocalFree(msg);
       }

       if (string_len) {
              *string_len = length-1;
       }

       return string;
}

Here is the caller graph for this function:

PHPAPI OLECHAR* php_com_string_to_olestring ( char *  string,
uint  string_len,
int codepage  TSRMLS_DC 
)

Definition at line 33 of file com_olechar.c.

{
       OLECHAR *olestring = NULL;
       DWORD flags = codepage == CP_UTF8 ? 0 : MB_PRECOMPOSED | MB_ERR_INVALID_CHARS;
       BOOL ok;

       if (string_len == -1) {
              /* determine required length for the buffer (includes NUL terminator) */
              string_len = MultiByteToWideChar(codepage, flags, string, -1, NULL, 0);
       } else {
              /* allow room for NUL terminator */
              string_len++;
       }

       if (string_len > 0) {
              olestring = (OLECHAR*)safe_emalloc(string_len, sizeof(OLECHAR), 0);
              ok = MultiByteToWideChar(codepage, flags, string, string_len, olestring, string_len);
       } else {
              ok = FALSE;
              olestring = (OLECHAR*)emalloc(sizeof(OLECHAR));
              *olestring = 0;
       }

       if (!ok) {
              char *msg = php_win_err(GetLastError());

              php_error_docref(NULL TSRMLS_CC, E_WARNING,
                     "Could not convert string to unicode: `%s'", msg);

              LocalFree(msg);
       }

       return olestring;
}

Here is the caller graph for this function: