Class: WIN32OLE_EVENT

Class | WIN32OLE_EVENT
In: | win32ole/win32ole.c
Parent: | Object

`WIN32OLE_EVENT` objects controls OLE event.

### Methods

message_loop new on_event on_event_with_outargs

### Public Class methods

WIN32OLE_EVENT.message_loop

Translates and dispatches Windows message.

[Source]

    /*
     *  call-seq:
     *     WIN32OLE_EVENT.message_loop
     *
     *  Translates and dispatches Windows message.
     */
    static VALUE
    fev_s_msg_loop(klass)
        VALUE klass;
    {
        ole_msg_loop();
        return Qnil;
    }

WIN32OLE_EVENT.new(ole, event) #=> WIN32OLE_EVENT object.

Returns OLE event object. The first argument specifies WIN32OLE object. The second argument specifies OLE event name.

       ie = WIN32OLE.new('InternetExplorer.Application')
       ev = WIN32OLE_EVENT.new(ie, 'DWebBrowserEvents')

[Source]

    /*
     *  call-seq:
     *     WIN32OLE_EVENT.new(ole, event) #=> WIN32OLE_EVENT object.
     *
     *  Returns OLE event object.
     *  The first argument specifies WIN32OLE object.
     *  The second argument specifies OLE event name.
     *     ie = WIN32OLE.new('InternetExplorer.Application')
     *     ev = WIN32OLE_EVENT.new(ie, 'DWebBrowserEvents')
     */
    static VALUE
    fev_initialize(argc, argv, self)
        int argc;
        VALUE *argv;
        VALUE self;
    {
        VALUE ole, itf;
        struct oledata *pole;
        char *pitf;
        HRESULT hr;
        IID iid;
        ITypeInfo *pTypeInfo;
        IDispatch *pDispatch;
        IConnectionPointContainer *pContainer;
        IConnectionPoint *pConnectionPoint;
        IEVENTSINKOBJ *pIEV;
        DWORD dwCookie = 0;
        struct oleeventdata *poleev;

        rb_secure(4);
        rb_scan_args(argc, argv, "11", &ole, &itf);

        if (!rb_obj_is_kind_of(ole, cWIN32OLE)) {
            rb_raise(rb_eTypeError, "1st parameter must be WIN32OLE object");
        }

        if(TYPE(itf) != T_NIL) {
            if (ruby_safe_level > 0 && OBJ_TAINTED(itf)) {
                rb_raise(rb_eSecurityError, "Insecure Event Creation - %s",
                         StringValuePtr(itf));
            }
            Check_SafeStr(itf);
            pitf = StringValuePtr(itf);
            hr = find_iid(ole, pitf, &iid, &pTypeInfo);
        }
        else {
            hr = find_default_source(ole, &iid, &pTypeInfo);
        }
        if (FAILED(hr)) {
            ole_raise(hr, rb_eRuntimeError, "interface not found");
        }

        OLEData_Get_Struct(ole, pole);
        pDispatch = pole->pDispatch;
        hr = pDispatch->lpVtbl->QueryInterface(pDispatch,
                                               &IID_IConnectionPointContainer,
                                               (void**)&pContainer);
        if (FAILED(hr)) {
            OLE_RELEASE(pTypeInfo);
            ole_raise(hr, rb_eRuntimeError,
                      "failed to query IConnectionPointContainer");
        }

        hr = pContainer->lpVtbl->FindConnectionPoint(pContainer,
                                                     &iid,
                                                     &pConnectionPoint);
        OLE_RELEASE(pContainer);
        if (FAILED(hr)) {
            OLE_RELEASE(pTypeInfo);
            ole_raise(hr, rb_eRuntimeError, "failed to query IConnectionPoint");
        }
        pIEV = EVENTSINK_Constructor();
        pIEV->m_iid = iid;
        hr = pConnectionPoint->lpVtbl->Advise(pConnectionPoint,
                                              (IUnknown*)pIEV,
                                              &dwCookie);
        if (FAILED(hr)) {
            ole_raise(hr, rb_eRuntimeError, "Advise Error");
        }

        Data_Get_Struct(self, struct oleeventdata, poleev);
        poleev->pEvent = pIEV;
        poleev->pEvent->m_event_id
            = NUM2INT(rb_funcall(ary_ole_event, rb_intern("length"), 0));
        poleev->pEvent->pConnectionPoint = pConnectionPoint;
        poleev->pEvent->pTypeInfo = pTypeInfo;
        poleev->pEvent->m_dwCookie = dwCookie;
        poleev->freed = 0;
        poleev->pEvent->ptr_freed = &(poleev->freed);
        rb_ary_push(ary_ole_event, self);
        return self;
    }

### Public Instance methods

WIN32OLE_EVENT#on_event([event]){...}

Defines the callback event. If argument is omitted, this method defines the callback of all events.

      ie = WIN32OLE.new('InternetExplorer.Application')
      ev = WIN32OLE_EVENT.new(ie, 'DWebBrowserEvents')
      ev.on_event("NavigateComplete") {|url| puts url}

[Source]

    /*
     *  call-seq:
     *     WIN32OLE_EVENT#on_event([event]){...}
     *
     *  Defines the callback event.
     *  If argument is omitted, this method defines the callback of all events.
     *    ie = WIN32OLE.new('InternetExplorer.Application')
     *    ev = WIN32OLE_EVENT.new(ie, 'DWebBrowserEvents')
     *    ev.on_event("NavigateComplete") {|url| puts url}
     */
    static VALUE
    fev_on_event(argc, argv, self)
        int argc;
        VALUE *argv;
        VALUE self;
    {
        return ev_on_event(argc, argv, self, Qfalse);
    }

WIN32OLE_EVENT#on_event_with_outargs([event]){...}

Defines the callback of event. If you want modify argument in callback, you should use this method instead of WIN32OLE_EVENT#on_event.

[Source]

    /*
     *  call-seq:
     *     WIN32OLE_EVENT#on_event_with_outargs([event]){...}
     *
     *  Defines the callback of event.
     *  If you want modify argument in callback,
     *  you should use this method instead of WIN32OLE_EVENT#on_event.
     */
    static VALUE
    fev_on_event_with_outargs(argc, argv, self)
        int argc;
        VALUE *argv;
        VALUE self;
    {
        return ev_on_event(argc, argv, self, Qtrue);
    }

[Validate]