durs / node-activex

Node.JS Implementaion of ActiveXObject
MIT License
329 stars 62 forks source link

function cannot be called. #126

Open GoodZivi opened 1 year ago

GoodZivi commented 1 year ago

Hi,I am a beginner.I had a problem using winax.Could you help me please. Here is my code.

var winax = require('winax');
var myObj = new winax.Object('MFCACTIVEXCONTRO.MFCActiveXControl1Ctrl.1');
console.log(myObj)

Terminal output.

<ref *1> [Function: undefined] Dispatch {
  [__vars]: {},
  [__methods]: {
    AboutBox: { name: 'AboutBox', dispid: -552, invkind: 1, flags: 0, argcnt: 0 },
    multiply: { name: 'multiply', dispid: 1, invkind: 1, flags: 0, argcnt: 2 }
  },
  [__type]: [
    { name: 'AboutBox', dispid: -552, invkind: 1, flags: 0, argcnt: 0 },
    { name: 'multiply', dispid: 1, invkind: 1, flags: 0, argcnt: 2 }
  ],
  [__value]: [Circular *1],
  [__id]: 'MFCACTIVEXCONTRO.MFCActiveXControl1Ctrl.1'
}

I cannot call the function like this.How to call 'multiply' function?

var winax = require('winax');
var myObj = new winax.Object('MFCACTIVEXCONTRO.MFCActiveXControl1Ctrl.1');
console.log(myObj.multiply(3,5))

Terminal output

console.log(myObj.multiply(3,5))
                  ^

Error: DispInvoke: multiply    catastrophic failure

    at Dispatch.<anonymous> (<anonymous>)
    at Object.<anonymous> (D:\Items\test\a.js:3:19)
    at Module._compile (node:internal/modules/cjs/loader:1254:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1308:10)
    at Module.load (node:internal/modules/cjs/loader:1117:32)
    at Module._load (node:internal/modules/cjs/loader:958:12)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12)
    at node:internal/main/run_main_module:23:47 {
  errno: -2147418113
}

Am i use it incorrectly? At last, I am so sorry for my poor English.

durs commented 1 year ago

That's right, but weird, Catastrophic Failure (Error 0x8000FFFF) occurs when calling DispInvoke with dispid=1

GoodZivi commented 1 year ago

Hi,durs. According to the question I search.I think I have found the reason. Before Ole4.0,External programs can directly call methods in OCX. After Ole4.0, every time a method in a control is called, the system will automatically check whether it is allowed to be called, that is, run 'COleControl. IsInvokeAllowed (DISPID)'

This method checks whether the control is properly initialized or loaded through a persistent storage interface. If one of the two conditions is met, it returns TRUE, otherwise it returns FALSE.

When using controls in MFC, many details, such as initialization, are filtered out, so that most users will not encounter this problem.

But when I call the function in node, it return false.

The solution is to overwrite this method again like this: ''' BOOL CMyNameCtrl::IsInvokeAllowed (DISPID) {

  return TRUE;

} ''' This work is difficult for me, because the ocx file is provided by another corporation.Finally, I changed my approach to solving this matter without node.

minkee-lee commented 1 year ago

Dear @GoodZivi,
I got the same issue and your research gave me an understanding. Thank you. But this is still problem for me. So did you find the another solution ? Then could you share how to? Thank you.