node-activex
node-activex copied to clipboard
js Callback Function causes Access Violation
Hi durs,
first of all, thanks for implementing 'winax'.
I currently use it to migrate software from IE to electron. Unfortunately I experience access violations when setting a javascript function as a callback for a C# object.
Example:
C# Site:
public interface IMyInterface { [DispId(0x1234567)] object OnChange { set; } }
JS Site:
function SetCallbackToInterface(callback) { myInterface.OnChange = function (eventName, eventData, eventTime) { if (eventName === "specialEvent") callback(eventName, eventData, eventTime); else __default(eventName, eventData, eventTime); }; }
Setting myInterface.OnChange to the Function above works, but when it is invoked from C# site it causes an access violation.
You already have a VarArguments implementation with *VarArguments(Isolate isolate, const FunctionCallbackInfo<Value> &args) but I am not sure how to use it correctly. When bool DispObject::set is called for the example above it should figure out if value is a function and then use the constructor using FunctionCallbackInfo. Could you help me please.
Hi durs,
I think the problem is, that Isolate::GetCurrent() returns NULL in DispObjectImpl::Invoke. Then the call to obj.Get(isolate) causes the Access Violation. Is it possible that GetCurrent() returns NULL because it's another thread?
Best regards, jobe
node-activex does not seem to work in an multithreaded environment.
yes, what is multithreaded environment in nodejs, for example?
I use node-activex in an electron project. I modified DllMain of your module to call CoInitializeEx instead of CoInitialize to make COM use a multithreaded apartment. Each object of IMyInterface (see example above) spawns a worker thread and from within this worker thread it calls a callback set by OnChange (see above) and unfortunately this leads to a crash because Isolate::GetCurrent returns NULL. I also modified DispObjectImpl that it stores the Isolate on which it was created, but this also leads to access violations. Do you have an idea how to cope with this?
Best regards, jobe