Wisend function
向指定线程发送标志通知值
Function:
bool UAPI Wisend(
int idThread,
dword dwFlags,
dword dwValue
);
Parameters:
- (int) idThread:目标线程ID,如为 NULL 则为当前进程的主线程
- (dword) dwFlags:标志,可以是以下标志中的一个或任意数值
| Constant | Value | Notes |
|---|---|---|
| WI_EXIT_THREAD | 0xFA1 | 退出线程 |
| WI_EXIT_PROCESS | 0xFA2 | 退出进程 |
- (dword) dwValue:值,可以是 NULL 或任意数值
Return value:
- Type:BOOL
- Text:成功返回 TRUE,失败返回 FALSE
Remarks:
Wisend function 仅将通知投递至指定线程,并不代表其线程会及时正确的处理该通知
Wisend function 通常用于线程之间通知,但也支持跨进程间线程通知,但不符合开发标准
跨进程之间通知应使用 SendNotify function 或 PostNotify function,而不是 Wisend function
可以向当前进程主线程发送 WI_EXIT_PROCESS 标志以安全退出当前进程,前提是应在 hello function 中使用 Wiget 获取该标志
C++ Code:
#include <h.studio>
int hello(){
if(Wiget(WI_EXIT_PROCESS) == WI_OK){
// Clean up the resources used by the process and return the main thread to exit the current process safely
}
return 0;
}
C++ Code:
#include <h.studio>
#include <h.thread>
int hello(){
int body();
int hThread = NewThread(&body,NULL,FALSE);
if(hThread!=NULL){
output("Create thread successfully and wait for the thread's exit notification...");
if(Wiget(WI_EXIT_PROCESS) == WI_OK){
CloseThread(hThread);
}
}else{
output("Failed to create thread");
}
return 0;
}
int body(){
sleep(1000);
Wisend(NULL,WI_EXIT_PROCESS,NULL); // Send a flag to the main thread for the exit process
return 0;
}