Native Node.js addon callback error - The specified procedure could not be found

257 Views Asked by At

I am writing a custom Node.js addon. Everything works dandy except for the use of callbacks. I have a method in a DLL that requires registering a C++ function callback - it takes a function, and then calls it when it receives new data, which is simple enough. What I'd like to do is in my .cc file, pass a local method through, and when that method is triggered, call the JavaScript callback. Calling the JavaScript callback on it's own, and saving the callback and calling it later works fine.

in my addon.cc, I have a method that does nothing except call a saved callback:

 static int __stdcall ReadCallback(RESULT* pResult){
 const unsigned argc = 1;
 v8::Local<v8::Value> argv[argc] =  { Nan::New("bah").ToLocalChecked() };
 Nan::MakeCallback(Nan::GetCurrentContext()->Global(), callback, argc, argv);
   return 0;
}

I have an exposed node method that is callable:

void RunCallback(const Nan::FunctionCallbackInfo<v8::Value>& info) {
   PipsLibrary::Functions::RegisterReadCallback(ReadCallback);
   v8::Local<v8::Function> cb = info[0].As<v8::Function>();
   callback = cb;
}

All of my other node methods calling through to the external C++ .DLL work, it's just passing this function as an argument from the .cc throws an error on run, "Uncaught Error: The specified procedure could not be found."

Not sure what the problem is, or if I can actually specify a method in the .cc file to pass through to C++ as a callback.

0

There are 0 best solutions below