You could pass the address of the callback
:
BOOL CALLBACK EnumWindowsProc(HWND hWnd, LPARAM lParam)
{
Local<Function>& f = *reinterpret_cast<Local<Function>*>(lParam);
// use f
return true;
}
Handle<Value> EnumWindows(const Arguments& args)
{
HandleScope scope;
// store callback function
auto callback = Local<Function>::Cast(args[0]);
// enum windows
auto result = EnumWindows(EnumWindowsProc,
reinterpret_cast<LPARAM>(&callback));
return scope.Close(Boolean::New(result == 1));
}
Another option would be just collecting the handles to process them later:
BOOL CALLBACK EnumWindowsProc(HWND hWnd, LPARAM lParam)
{
std::vector<HWND>* p = reinterpret_cast<std::vector<HWND>*>(lParam);
p->push_back(hWnd);
return true;
}
Handle<Value> EnumWindows(const Arguments& args)
{
HandleScope scope;
// store callback function
auto callback = Local<Function>::Cast(args[0]);
// enum windows
std::vector<HWND> handles;
auto result = EnumWindows(EnumWindowsProc,
reinterpret_cast<LPARAM>(&handles));
// Do the calls...
return scope.Close(Boolean::New(result == 1));
}