_library._preload['zend_llist_apply_with_del'] = ['zend_llist', 'int (void *)', function () {
    _library.zend_llist_apply_with_del = ['void', [ref.refType(_library.zend_llist), ffi.Function('int', [ref.refType('void')])]];
    _library._functions['zend_llist_apply_with_del'] = _library.zend_llist_apply_with_del;
}];
_library._preload['zend_llist_apply_with_argument'] = ['zend_llist', 'llist_apply_with_arg_func_t', function () {
    _library.zend_llist_apply_with_argument = ['void', [ref.refType(_library.zend_llist), _library.llist_apply_with_arg_func_t, ref.refType('void')]];
    _library._functions['zend_llist_apply_with_argument'] = _library.zend_llist_apply_with_argument;
}];
_library._preload['zend_llist_copy'] = ['zend_llist', 'zend_llist', function () {
    _library.zend_llist_copy = ['void', [ref.refType(_library.zend_llist), ref.refType(_library.zend_llist)]];
    _library._functions['zend_llist_copy'] = _library.zend_llist_copy;
}];
_library._preload['zend_llist_apply'] = ['zend_llist', 'llist_apply_func_t', function () {
    _library.zend_llist_apply = ['void', [ref.refType(_library.zend_llist), _library.llist_apply_func_t]];
    _library._functions['zend_llist_apply'] = _library.zend_llist_apply;
}];
    size: ref.sizeof.pointer,
    get: function (buffer, offset) {
        var buf = buffer.readPointer(offset);
        if (buf.isNull()) {
            return null;
        }
        return buf.readCString(0);
    },
    set: function (buffer, offset, value) {
        var buf = ref.allocCString(value, 'ucs2');
        return buffer.writePointer(buf, offset);
    },
    ffi_type: ffi.types.CString.ffi_type
};

var lpdwordPtr = ref.refType(ref.types.ulong);

var user32 = ffi.Library('user32', {
	EnumWindows: ['bool', ['pointer', 'int']],
	GetWindowTextW: ['int', ['int', 'pointer', 'int']],
    SendMessageW: ['int', ['int', 'int', 'int', 'int']]
});

function getWindowList(windowTitle) {

    function strOfLength(size) {
        var str = "";
        var i;
        for (i = 0; i < size; i++) {
            str += " ";
        }
_library._preload['php_stream_open_for_zend_ex'] = ['zend_file_handle', function () {
    _library.php_stream_open_for_zend_ex = ['int', [ref.refType('char'), ref.refType(_library.zend_file_handle), 'int']];
    _library._functions['php_stream_open_for_zend_ex'] = _library.php_stream_open_for_zend_ex;
}];
_library._preload['php_lint_script'] = ['zend_file_handle', function () {
    _library.php_lint_script = ['int', [ref.refType(_library.zend_file_handle)]];
    _library._functions['php_lint_script'] = _library.php_lint_script;
}];
_library._preload['zend_llist_sort'] = ['zend_llist', 'llist_compare_func_t', function () {
    _library.zend_llist_sort = ['void', [ref.refType(_library.zend_llist), _library.llist_compare_func_t]];
    _library._functions['zend_llist_sort'] = _library.zend_llist_sort;
}];
_library._preload['php_register_extensions'] = ['pointer', function () {
    _library.php_register_extensions = ['int', [ref.refType(ref.refType(_library.zend_module_entry)), 'int']];
    _library._functions['php_register_extensions'] = _library.php_register_extensions;
}];
_library._preload['php_execute_simple_script'] = ['zend_file_handle', 'pointer', function () {
    _library.php_execute_simple_script = ['int', [ref.refType(_library.zend_file_handle), ref.refType(ref.refType(_library.zval))]];
    _library._functions['php_execute_simple_script'] = _library.php_execute_simple_script;
}];
_library._preload['php_request_shutdown_for_hook'] = [function () {
    _library.php_request_shutdown_for_hook = ['void', [ref.refType('void')]];
    _library._functions['php_request_shutdown_for_hook'] = _library.php_request_shutdown_for_hook;
}];
_library._preload['php_module_shutdown_wrapper'] = ['sapi_module_struct', function () {
    _library.php_module_shutdown_wrapper = ['int', [ref.refType(_library.sapi_module_struct)]];
    _library._functions['php_module_shutdown_wrapper'] = _library.php_module_shutdown_wrapper;
}];
_library._preload['php_module_startup'] = ['sapi_module_struct', 'zend_module_entry', function () {
    _library.php_module_startup = ['int', [ref.refType(_library.sapi_module_struct), ref.refType(_library.zend_module_entry), 'uint']];
    _library._functions['php_module_startup'] = _library.php_module_startup;
}];
_library._preload['_zend_llist_element'] = ['_zend_llist_element', '_zend_llist_element', function () {
    _library._zend_llist_element.size = 0;
    _library._zend_llist_element.defineProperty("next", ref.refType(_library._zend_llist_element));
    _library._zend_llist_element.defineProperty("prev", ref.refType(_library._zend_llist_element));
    _library._zend_llist_element.defineProperty("data", _library.__RefArray('char', 1));
}];
_library._preload['php_handle_auth_data'] = [function () {
    _library.php_handle_auth_data = ['int', [ref.refType('char')]];
    _library._functions['php_handle_auth_data'] = _library.php_handle_auth_data;
}];
_library._preload['zend_llist_count'] = ['zend_llist', function () {
    _library.zend_llist_count = ['int', [ref.refType(_library.zend_llist)]];
    _library._functions['zend_llist_count'] = _library.zend_llist_count;
}];
_library._preload['php_html_puts'] = [function () {
    _library.php_html_puts = ['void', [ref.refType('char'), 'uint']];
    _library._functions['php_html_puts'] = _library.php_html_puts;
}];
_library._preload['zend_llist_get_last_ex'] = ['zend_llist', 'zend_llist_position', function () {
    _library.zend_llist_get_last_ex = [ref.refType('void'), [ref.refType(_library.zend_llist), ref.refType(_library.zend_llist_position)]];
    _library._functions['zend_llist_get_last_ex'] = _library.zend_llist_get_last_ex;
}];
var ref = require('ref');
var ffi = require('ffi');
var Struct = require('ref-struct');
var ArrayType = require('ref-array');

// basic type
var void_type = ref.types.void;
var bool = ref.types.bool;
var int = ref.types.int;
var int32 = ref.types.int32;
var int16 = ref.types.int16;
var uint8 = ref.types.uint8;
var string = ref.types.CString;

// basic pointer
var void_ptr = ref.refType(void_type);
var int_ptr = ref.refType(int);

// global define
var SDL_Joystick = void_type;
var SDL_JoystickGUID = Struct({
	data: ArrayType(uint8, 16)
});
var SDL_JoystickID = int32;
var SDL_HAT_CENTERED = 0x00;
var SDL_HAT_UP = 0x01;
var SDL_HAT_RIGHT = 0x02;
var SDL_HAT_DOWN = 0x04;
var SDL_HAT_LEFT = 0x08;
var SDL_HAT_RIGHTUP = (SDL_HAT_RIGHT|SDL_HAT_UP);
var SDL_HAT_RIGHTDOWN = (SDL_HAT_RIGHT|SDL_HAT_DOWN);