📄 w32api.c
字号:
dp->width = width; } else { int width= 0; dp->argument_ptr = php_w32api_complex_marshall_zval_to_c(pzval, &width, NULL TSRMLS_CC); dp->width = width; } break; case W32API_UNKNOWN: php_error(E_ERROR, "Unknown type when calling function, marshalling failed"); break; }}static void *php_w32api_complex_marshall_zval_to_c(zval *pzval, int *width, void *return_value TSRMLS_DC){ w32api_type_instance *th; zval **type_instance_handle; members *current_member; char *offset = return_value; int i = 0; if(return_value == NULL) { /* First call *//* return_value = emalloc(th->type->size); zend_hash_index_find(Z_OBJPROP_P(object), 0, (void **) &type_instance_handle); th = (w32api_type_instance *)zend_fetch_resource(type_instance_handle TSRMLS_CC, -1, "Complex Type Instance", NULL, 1, WG(le_type_instance)); if(!th) return NULL; for(i = 0; i < th->type->member_count; i++) { }*/ } }/* ===================================================================================================== * Win32 Class Code * ===================================================================================================== *//* {{{ win32_class_functions[] */function_entry win32_class_functions[] = { W32API_CLASS_FE(win32, registerfunction, NULL) W32API_CLASS_FE(win32, unregisterfunction, NULL) W32API_CLASS_FE(win32, registercallback, NULL) W32API_CLASS_FE(win32, definetype, NULL) W32API_CLASS_FE(win32, gettypesize, NULL) W32API_CLASS_FE(win32, inittype, NULL) W32API_CLASS_FE(win32, decref, NULL)#ifndef NDEBUG W32API_CLASS_FE(win32, dump_function_hash, NULL) W32API_CLASS_FE(win32, dump_library_hash, NULL) W32API_CLASS_FE(win32, dump_callback_hash, NULL) W32API_CLASS_FE(win32, dump_type_hash, NULL)#endif {NULL, NULL, NULL}};/* }}} *//* {{{ win32_class_init(TSRMLS_D) */int win32_class_init(TSRMLS_D){ zend_class_entry ce; INIT_CLASS_ENTRY(ce, "win32", win32_class_functions); WG(win32_ce) = zend_register_internal_class(&ce TSRMLS_CC); return SUCCESS;}/* }}} *//* {{{ win32_class_rshutdown(TSRMLS_D) * Cleans up at the end of the shutdown removing and freeing anything we added to the function * table. */int win32_class_rshutdown(TSRMLS_D){ return SUCCESS;}/* }}} *//* {{{ proto: int Win32::RegisterFunction(string definition [, int flags]) * Registers and Loads a function from an underlying Dll */W32API_CLASS_FUNCTION(win32, registerfunction){ char *function_definition = NULL; int function_definition_len; long flags = 0; if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|l", &function_definition, &function_definition_len, &flags) == FAILURE) { return; } if(php_w32api_load_function(function_definition, function_definition_len, flags TSRMLS_CC) != SUCCESS) { php_error(E_ERROR, "Registering Function %s failed", function_definition); RETURN_FALSE; } RETURN_TRUE;}/* }}} *//* {{{ proto: int Win32::UnregisterFunction(string function_name) * Unregisters a previously loaded function */W32API_CLASS_FUNCTION(win32, unregisterfunction){ char *function_name = NULL; int function_name_len; w32api_func_handle **fh = NULL; if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &function_name, &function_name_len) == FAILURE) { return; } /* Our deleteor handler removes us from the WG(win32_ce)->function_table * so no need to delete specifically from there */ zend_hash_del(WG(funcs), function_name, strlen(function_name) + 1); RETURN_TRUE;}/* }}} *//* {{{ proto: int Win32::RegisterCallback(string definition) * Registers a callback type */W32API_CLASS_FUNCTION(win32, registercallback){ char *function_definition = NULL; int function_definition_len; w32api_func_handle **fh = NULL; if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &function_definition, &function_definition_len) == FAILURE) { return; } if(php_w32api_register_callback(function_definition, function_definition_len TSRMLS_CC) != SUCCESS) { RETURN_FALSE; } RETURN_TRUE;}/* }}} *//* {{{ proto: int Win32::DefineType(string definition) * Defines a C Like Type for use. */W32API_CLASS_FUNCTION(win32, definetype){ char *type_definition = NULL; int type_definition_len; if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &type_definition, &type_definition_len) == FAILURE) { return; } if(php_w32api_register_type(type_definition, type_definition_len TSRMLS_CC) != SUCCESS) { php_error(E_ERROR, "Registering Type %s failed", type_definition); RETURN_FALSE; } RETURN_TRUE;}/* }}} *//* {{{ proto: int Win32::GetTypeSize(string type_name) * Returns the size of a registered type */W32API_CLASS_FUNCTION(win32, gettypesize){ char *type = NULL; int type_len; if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &type, &type_len) == FAILURE) { return; } RETURN_LONG(php_w32api_get_type_size(php_w32api_get_type_id_from_name(type), type, BYREF_NONE)); }/* }}} *//* {{{ proto: int Win32::InitType(string TypeName) * Creates an instance of type TypeName */W32API_CLASS_FUNCTION(win32, inittype){ char *type_name = NULL; int type_name_len = 0; w32api_type_handle **th = NULL; if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &type_name, &type_name_len) == FAILURE) { return; } if(zend_hash_find(WG(types), type_name, type_name_len +1, (void **)&th) == FAILURE) { php_error(E_ERROR, "Could not retrieve type handle for type %s from hash table", type_name); RETURN_FALSE; } php_w32api_init_type(*th, return_value TSRMLS_CC);}/* }}} *//* {{{ proto: int Win32::DecRef(mixed Variable) * Decreases the reference count on a variable */W32API_CLASS_FUNCTION(win32, decref){}/* }}} *//* {{{ XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX * THIS FUNCTION IS NOT PUBLICALLY ACCESSABLE * IT IS USED AS A GENERIC HANDLER FOR W32API * CALLS. */W32API_CLASS_FUNCTION(win32, invokefunction){ char *function_name = get_active_function_name(TSRMLS_C); int argc = ZEND_NUM_ARGS(); int i = 0; w32api_dynamic_param *params = NULL; w32api_dynamic_param *current_dynamic_param = NULL; w32api_func_handle **fh = NULL; w32api_result res = {0}; void *w32api_return_buffer = NULL; int w32api_return_buffer_size = 0; zval **func_arguments = NULL; zval *current_zval = NULL; arguments *curr_arg = NULL; w32api_type_handle *th = NULL; if(zend_hash_find(WG(funcs), function_name, strlen(function_name) +1, (void **)&fh) == FAILURE) { php_error(E_ERROR, "Could not retrieve function handle from hash table"); RETURN_FALSE; } if(argc) { if(zend_get_parameters_array_ex(argc, &func_arguments) == FAILURE) { WRONG_PARAM_COUNT } params = (w32api_dynamic_param *)emalloc(sizeof(w32api_dynamic_param) * argc); curr_arg = (*fh)->argument_list; current_dynamic_param = params; for(i = 0; i < argc; i++) { current_zval = func_arguments[i]; php_w32api_marshall_zval_to_c(curr_arg->arg, current_dynamic_param, current_zval TSRMLS_CC); current_dynamic_param++; curr_arg = curr_arg->next_arg; } } else { params = NULL; } if((*fh)->return_type_id == W32API_COMPLEX) { if(zend_hash_find(WG(types), (*fh)->return_type_name, strlen((*fh)->return_type_name) +1, (void **)&th) != SUCCESS) php_error(E_ERROR, "Could not find type handle for type %s", (*fh)->return_type_name); w32api_return_buffer = emalloc(th->size); w32api_return_buffer_size = th->size; } res = php_w32api_do_dynamic_dll_call(*fh, argc, params, w32api_return_buffer, w32api_return_buffer_size); if(argc) /* We should demarshall here not just efree */ efree(params); switch((*fh)->return_type_id) { case W32API_LONG: RETURN_LONG(res.lval); break; case W32API_INT: RETURN_LONG(res.ival); break; case W32API_STRING: case W32API_BYTE: RETURN_STRING(res.ptr, 1); break; case W32API_DOUBLE: RETURN_DOUBLE(res.dval); break; case W32API_FLOAT: RETURN_DOUBLE(res.fval); break; case W32API_BOOL: if(res.ival) { RETURN_TRUE; } else { RETURN_FALSE; } break; case W32API_COMPLEX: break; default: php_error(E_WARNING, "Unknown return type %s", (*fh)->return_type_name); }}/* }}} */#ifndef NDEBUGW32API_CLASS_FUNCTION(win32, dump_library_hash){ zend_hash_apply(WG(libraries), (apply_func_t)php_w32api_dump_library_hash_cb TSRMLS_CC);}W32API_CLASS_FUNCTION(win32, dump_function_hash){ zend_hash_apply(WG(funcs), (apply_func_t)php_w32api_dump_function_hash_cb TSRMLS_CC);}W32API_CLASS_FUNCTION(win32, dump_callback_hash){ zend_hash_apply(WG(callbacks), (apply_func_t)php_w32api_dump_callback_hash_cb TSRMLS_CC);}W32API_CLASS_FUNCTION(win32, dump_type_hash){ zend_hash_apply(WG(types), (apply_func_t)php_w32api_dump_type_hash_cb TSRMLS_CC);}int php_w32api_dump_library_hash_cb(void *pData TSRMLS_DC){ w32api_lib_handle *lh = pData; printf("=====================================================================\n"); printf("Library Name: \t\t%s\n", lh->library_name); printf("Reference Count: \t\t%d\n", lh->ref_count); printf("Library Handle: \t\t%p\n", lh->handle); printf("Lib ptr loc \t\t%p\n", lh); printf("ll n loc \t\t%p\n", &lh->ref_count); printf("=====================================================================\n"); return 0;}int php_w32api_dump_function_hash_cb(void *pData TSRMLS_DC){ w32api_func_handle **fh = pData; printf("=====================================================================\n"); printf("Function Name: \t\t%s\n", (*fh)->function_name); printf("Return Type Name: \t\t%s\n", (*fh)->return_type_name); printf("Library Name: \t\t%s\n", (*fh)->lib->library_name ); printf("Function Flags: \t\t%d\n", (*fh)->flags); printf("Function Handle: \t\t%p\n", (*fh)->handle); printf("Return Type ID: \t\t%d\n", (*fh)->return_type_id); printf("Return Type Name: \t\t%s\n", (*fh)->return_type_name); printf("## Arguments ##\n"); printf("---------------------------------------------------------------------\n"); php_w32api_print_arguments((*fh)->argument_list); printf("=====================================================================\n\n"); return 0;}int php_w32api_dump_callback_hash_cb(void *pData TSRMLS_DC){ w32api_func_handle **fh = pData; printf("=====================================================================\n"); printf("Callback Name: \t\t%s\n", (*fh)->function_name); printf("Return Type Name: \t\t%s\n", (*fh)->return_type_name); printf("Callback Flags: \t\t%d\n", (*fh)->flags); printf("Return Type ID: \t\t%d\n", (*fh)->return_type_id); printf("Return Type Name: \t\t%s\n", (*fh)->return_type_name); printf("## Arguments ##\n"); printf("---------------------------------------------------------------------\n"); php_w32api_print_arguments((*fh)->argument_list); printf("=====================================================================\n\n"); return 0;}int php_w32api_dump_type_hash_cb(void *pData TSRMLS_DC){ w32api_type_handle **th = pData; printf("=====================================================================\n"); printf("Type Name: \t\t%s\n", (*th)->type_name);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -