v8, libuv, nodejs, win32 api - how to call EnumWindows and have callback call javascript function?

StackOverflow https://stackoverflow.com/questions/23209621

  •  07-07-2023
  •  | 
  •  

質問

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.

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.

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.

役に立ちましたか?

解決

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().

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.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top