node-activex icon indicating copy to clipboard operation
node-activex copied to clipboard

listen events from Object

Open pr0duc3r opened this issue 6 years ago • 8 comments

Hello,

I am using the winax to invoke methods in a COM Object and works fine. Now I need to listen to events of that Object. How should I get arround that? Thank you. Great job.

pr0duc3r avatar Jun 22 '18 22:06 pr0duc3r

Unfortunately, this requires the implementation of the native IUnknown interface, which is required by IConnectionPoint::Advise. But this is problematic in node javascript

сб, 23 июн. 2018 г. в 1:30, Leandro [email protected]:

Hello,

I am using the winax to invoke methods in a COM Object and works fine. Now I need to listen to events of that Object. How should I get arround that? Thank you. Great job.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/durs/node-activex/issues/32, or mute the thread https://github.com/notifications/unsubscribe-auth/AAjGNTW36EYN4EENvhcAaGkKPMGoY2J4ks5t_W_rgaJpZM4U0gLE .

durs avatar Jun 24 '18 20:06 durs

@durs You can do it bro!!! I need this feature.

drummerv avatar Jun 25 '18 12:06 drummerv

sorry, a universal solution does not work

durs avatar Jul 02 '18 15:07 durs

COM provides self-inspect mechanism. According to Qt QAxBase https://github.com/qt/qtactiveqt/blob/92b453c705c3259e03913002e5ab34d599647852/src/activeqt/container/qaxbase.cpp#L2792, I have built a demo project (https://github.com/asinbow/CppActiveXEventDemo) for listening ActiveX/COM event.

// Presudo code of https://github.com/asinbow/CppActiveXEventDemo/blob/master/CppActiveXEventDemo/CppActiveXEventDemo.cpp
application = CoCreateInstance(...);
typeLib = application->GetContainingTypeLib(...);

connectionPoints = application->QueryInterface(IID_IConnectionPointContainer);
for (connectionPoint of connectionPoints) { // in most case only one connection point
  typeInfo = typeLib->GetTypeInfoOfGuid(connectionPoint->GetConnectionInterface());
  typeAttr = typeInfo->GetTypeAttr(...);
  for (int i = 0; i < typeAttr->cFuncs; i++) { // event functions
    funcDesc = typeInfo->GetFuncDesc(i);
    names = typeInfo->GetNames(funcDesc->memid);
    funcName = names[0]; // function name
    for (int j = 1; j < names.size(); j++) {
      paramName = names[j]; // parameter name
      paramDesc = funcDesc->lprgelemdescParam[j - 1]; // parameter type and description
    }
  }

  connectionPoint->Advise(&eventHandler, ...); // listen to events of connectionPoint
}

class EventHandler : public IDispatch {
  // ...
  HRESULT Invoke(...) {
    // callback
    // TODO ...
    return S_OK;
  }
};

EventHandler eventHandler;

Maybe we can do something more. @durs How do you think about this? Would it work?

asinbow avatar Feb 19 '19 04:02 asinbow

https://github.com/durs/node-activex/pull/44

asinbow avatar Feb 21 '19 08:02 asinbow

Event listener is implemented in https://github.com/durs/node-activex/pull/46 And I am waiting for @durs 's suggestion.

And next step, we can do something more:

  1. implement Unadvise
  2. ensure no memory leak
  3. format code

asinbow avatar Feb 25 '19 09:02 asinbow

Hi

The events seem to work with the COM objects like Excel, InternetExplorer etc., but does NOT seem to work the custom COM component. I have been provided with a custom COM component. I'm able to call the methods and properties, but unable to register to the event.

Any help would be highly appreciated.

jkash20 avatar May 08 '20 04:05 jkash20

@asinbow also have problems with proprietary COM blob:

const IServerStartup = new winax.Object('Moagent32.IServerStartup');
const IMoagent = IServerStartup.PropIMoagent

const connectionPoints = winax.getConnectionPoints(IMoagent)
const connectionPoint = connectionPoints[0]

connectionPoint.advise({
    MosaixEvent: function (err_flag, notify_type, mosaix_data_packet, err_code, err_text) {
        console.log(mosaix_data_packet)
    }
})

Still getting -2147467262 (Interface not supported)...

From ITypeLib Viewer: изображение

savely-krasovsky avatar May 17 '20 21:05 savely-krasovsky