v8,libuv,nodejs,win32 api - 如何调用EnumWindows并具有回调调用javascript函数?

时间:2021-11-26 06:57:30

I'm trying to write a C++ library, using v8, for node.js. My only goal is to allow javascript to call EnumWindows, the win32 api function.

我正在尝试使用v8为node.js编写一个C ++库。我唯一的目标是允许javascript调用Win32 api函数EnumWindows。

The EnumWindows method itself takes a callback function as a parameter. It will call that function for every enumerated window, passing it the window handle.

EnumWindows方法本身将回调函数作为参数。它将为每个枚举窗口调用该函数,并将窗口句柄传递给它。

I'm trying to make it so that it calls a javascript function for every window handle, as well. Any ideas how to do this? libuv looked promising, but that looks like I have to be the one to be creating the thread. That's not the case here.

我正在努力使它为每个窗口句柄调用一个javascript函数。任何想法如何做到这一点? libuv看起来很有希望,但看起来我必须成为创建线程的人。这不是这里的情况。

1 个解决方案

#1


1  

Use uv_async_init() and uv_async_send(). You can attach your own data pointer to the uv_async_t's data member (e.g. uv_async_t foo; foo.data = someptr;). This is where you could store any data you need (e.g. information about the enumerated windows in your case) when signalling the main thread with uv_async_send().

使用uv_async_init()和uv_async_send()。您可以将自己的数据指针附加到uv_async_t的数据成员(例如,uv_async_t foo; foo.data = someptr;)。在使用uv_async_send()发信号通知主线程时,您可以在此处存储所需的任何数据(例如,在您的情况下有关枚举窗口的信息)。

Once inside the uv_async callback on the main thread, you can read from the same data member and call to to javascript with the v8 API.

进入主线程上的uv_async回调后,您可以从同一个数据成员读取并使用v8 API调用javascript。

#1


1  

Use uv_async_init() and uv_async_send(). You can attach your own data pointer to the uv_async_t's data member (e.g. uv_async_t foo; foo.data = someptr;). This is where you could store any data you need (e.g. information about the enumerated windows in your case) when signalling the main thread with uv_async_send().

使用uv_async_init()和uv_async_send()。您可以将自己的数据指针附加到uv_async_t的数据成员(例如,uv_async_t foo; foo.data = someptr;)。在使用uv_async_send()发信号通知主线程时,您可以在此处存储所需的任何数据(例如,在您的情况下有关枚举窗口的信息)。

Once inside the uv_async callback on the main thread, you can read from the same data member and call to to javascript with the v8 API.

进入主线程上的uv_async回调后,您可以从同一个数据成员读取并使用v8 API调用javascript。