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

using winax in nw.js with web worker

Open danielemarsico opened this issue 6 years ago • 7 comments

Hi,

I'm trying to user winax in a project with nw.js using WebWorker. I can load the module inside a webworker using

activex = require('node-activex');

and i works fine. But if another web worker wants to use the samemodule I get error: Module didnot self register.

My question is this module can be used ia multithreading application (like using webworker?) if so is there any setup to be done in advance?

Thank you! I love this project!

danielemarsico avatar Mar 25 '18 18:03 danielemarsico

Theoretically, multithreading is supported, but web workers can't require node modules and I do not find the opportunity to transfer winax it into the worker

2018-03-25 21:04 GMT+03:00 danielemarsico [email protected]:

Hi,

I'm trying to user winax in a project with nw.js using WebWorker. I can load the module inside a webworker using

activex = require('node-activex');

and i works fine. But if another web worker wants to use the samemodule I get error: Module didnot self register.

My question is this module can be used ia multithreading application (like using webworker?) if so is there any setup to be done in advance?

Thank you! I love this project!

— 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/24, or mute the thread https://github.com/notifications/unsubscribe-auth/AAjGNRDlMNarjGpK5Co_K5mlxPLA9_IUks5th9xIgaJpZM4S6PRx .

durs avatar Mar 26 '18 08:03 durs

You will have to use same Worker instantiated globally. Send different messages to execute different tasks on the worker. I have done it this way.

Avrohom avatar Jul 01 '18 00:07 Avrohom

Thank you for the feedback, I’m doing the same way, just trying to figure out how to centralize the management of the calls.

Daniele

Il giorno dom 1 lug 2018 alle 02:07 Avrohom [email protected] ha scritto:

You will have to use same Worker instantiated globally. Send different messages to execute different tasks on the worker. I have done it this way.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/durs/node-activex/issues/24#issuecomment-401574176, or mute the thread https://github.com/notifications/unsubscribe-auth/ABrxSC7gEx4qN4ElMzLhn0xPisM5b1eRks5uCBLBgaJpZM4S6PRx .

danielemarsico avatar Jul 04 '18 19:07 danielemarsico

Well I am fairly a newby when it comes to JavaScript.

But what I am doing is like following:

In both the Main thread AND in the worker thread I declare an enum like this: const operation = Object.freeze({ 'connect': 0, 'disconnect': 1, 'get_sdk_version': 2, 'another-function': 3, 'etc: 4 })

In the main (calling) I call any function on the Worker with JSON object containing a operation value and any args I may have, such as: worker.postMessage({ 'operation': operation.connect, 'whatever_arg': 'my argument' })

In the worker thread: `onmessage = function (e) {

var opp = e.data.operation

switch (opp) {

    case operation.connect:

        var file_path = e.data.whatever_arg

        // do function and return postMessage when completed with result inside a JSON

       break

    case operation.disconnect:

      do_disconnect();

      break

    case etc

    end so forth...

`

Avrohom avatar Jul 05 '18 02:07 Avrohom

Got the same issue using worker threads. The first time the thread requires the module it works fine and ActiveX object are loaded correctly. Second thread gets

Error: Module did not self-register. at Object.Module._extensions..node (internal/modules/cjs/loader.js:805:18) at Module.load (internal/modules/cjs/loader.js:653:32) at tryModuleLoad (internal/modules/cjs/loader.js:593:12) at Function.Module._load (internal/modules/cjs/loader.js:585:3) at Module.require (internal/modules/cjs/loader.js:690:17) at require (internal/modules/cjs/helpers.js:25:18) at Object. (node_modules\winax\activex.js:1:32) at Module._compile (internal/modules/cjs/loader.js:776:30) at Object.Module._extensions..js (internal/modules/cjs/loader.js:787:10) at Module.load (internal/modules/cjs/loader.js:653:32) Emitted 'error' event at: at Worker.[kOnErrorMessage] (internal/worker.js:333:10) at Worker.[kOnMessage] (internal/worker.js:343:37) at MessagePort.Worker.(anonymous function).on (internal/worker.js:279:57) at MessagePort.emit (events.js:198:13) at MessagePort.onmessage (internal/worker.js:84:8)

Is there any way to use activeX objects with threads ? I could not find a way to require it only once and pass the instance to the worker.

kukraPOC avatar Jul 04 '19 20:07 kukraPOC

Hi Durs Thanks for the fantastic effort in developing this utility Any news on making it thread compatible ?

Ajitweb avatar Jul 29 '20 08:07 Ajitweb

After a gap of almost two years back, I tried it with latest Node. winax is now working smoothly with worker_threads module of node js

Ajitweb avatar Mar 28 '22 14:03 Ajitweb