Page 1 of 1

IEventListener problem.

Posted: 3. Feb 2016, 07:26
by Lezh1k
Hi all .
I want to get some events from VBox. On linux machine both active and passive listeners work. I mean I can get and handle events. But on windows machine neither of them don't work. I've tried to use source code from VBoxHeadlessTray, but it doesn't work too.
In passive mode I always have NULL. In active mode nothing happens.

Code: Select all

CVBoxManagerWin::CVBoxManagerWin() :
  m_virtual_box(NULL),
  m_event_source(NULL),
  m_event_listener(NULL)
{
#define CHECK_RES(x) if (FAILED(m_last_error)) {m_last_vb_error = x; break;}
  do {
    m_last_error = CoInitialize(NULL);
    CHECK_RES(VBE_INIT_XPCOM2);

    m_last_error = CoCreateInstance(CLSID_VirtualBox,
                                    NULL,
                                    CLSCTX_LOCAL_SERVER,
                                    IID_IVirtualBox,
                                    (void**)&m_virtual_box);
    CHECK_RES(VBE_CREATE_VIRTUAL_BOX);

    m_last_error = m_virtual_box->get_EventSource(&m_event_source);
    CHECK_RES(VBE_EVENT_SOURCE);    

    m_last_error = m_event_source->CreateListener(&m_event_listener);
    CHECK_RES(VBE_EVENT_LISTENER);

    SAFEARRAYBOUND bound;
    bound.lLbound = 0;
    bound.cElements = m_dct_event_handlers.size();

    SAFEARRAY* safe_interested = SafeArrayCreate(VT_INT, 1, &bound);
    LONG index = 0;
    for (auto i = m_dct_event_handlers.cbegin(); i != m_dct_event_handlers.cend(); ++i, ++index) {
      SafeArrayPutElement(safe_interested, &index, (void*)&i->first);
    }

    m_last_error = m_event_source->RegisterListener(m_event_listener,
                                                    safe_interested,
                                                    VARIANT_FALSE);

    CHECK_RES(VBE_REGISTER_LISTENER);
  } while (false);
#undef CHECK_RES
}


There is one element in m_dct_event_handlers : VBoxEventType_Any.


BTW : List of VMs, turn on/off VM works. But IEventListener - doesn't. What do I do wrong?

PS:
Virtual Box version : 5.0.14 r105127
Windows 7 - x64
VC2013 compiler.