durs / node-activex

Node.JS Implementaion of ActiveXObject

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

How to attach to an existing IDispatch pointer

somanuell opened this issue · comments

Hi durs,
I have a situation where an Excel is not correctly saved in the ROT, but I think I can retrieve an IDispatch* by other means (using an MSAA technique). Could I then somehow "inject" the IDispatch pointer into winax?

Ok, fund code in disp.cpp line 547:

	// Use supplied dispatch pointer
	else if (args[0]->IsUint8Array()) {
        size_t len = node::Buffer::Length(args[0]);
        void *data = node::Buffer::Data(args[0]);
        IDispatch *p = (len == sizeof(INT_PTR)) ? (IDispatch *) *(static_cast<INT_PTR*>(data)) : nullptr;
        if (!p) {
            isolate->ThrowException(InvalidArgumentsError(isolate));
            return;
        }
		disp.Attach(p);
		hrcode = S_OK;
	}

Issue now is "HOW TO" to pass the pointer from JavaScript ???

Hi, found this example:

// Create COM object from JS
var obj = new winax.Object({
    test: function(v) { return v*2; }
});

// Convert COM IDispatch pointer to Variant array
var varr = new winax.Variant(obj, 'uint8[]');

// Convert Variant array to JS array address bytes
var arr = new Uint8Array(varr.valueOf());
console.log(arr);

// Create new COM object from IDispatch pointer (address bytes)
var obj2 = new winax.Object(arr);

// Call test method
console.log(obj2.test(2));

@durs Hi. Thanks for merging the PR. Do you plan to release on npmjs.com?

Ok, I'll make a release, while I don't plan to change anything else

Hi, again. When I built winax with npm i against node 14.18.3 in january 2022, I got a node_activex.node of approx 185 kB. Today when I npm i winax against node 14.20.0 I get a node_activex.node of 560 kB! What am I missing here?

I don't know, last release in my environment 240 Kb with Node 18.13 and Visual Studio 2022 (v143)

What is your build method?

npm install
then tried rebuild binding.sln but got the same result

Same here! npm install ==> node_activex.node is 544 KB
rebuild binding.sln ==> node_activex.node is 544 KB....
node --version ==> v14.20.0
Visual Studio 2022 (v143)
I AM LOST!

LOL with nodejs v18.15.0 32 bits I am now at 194 KB!
Something very weird is happening with the LIBs used while linking against nodejs v14.20....