关于IsAPIReady:
来自MSDN的诠释:This function indicates whether the specified application programming interface (API) set has been registered. This function uses a polling mechanism.
BOOL IsAPIReady(
DWORD hAPI
);
Parameters:
由于它是使用查询式的工作方式,而我是希望在某一个API Ready之后,才继续执行之后的代码 ,所以需要在使用的时候需要去进行一些处理。
...
while (true)
{
if (IsAPIReady(hHandle))
{
break;
}
else
{
Sleep(100);
}
}
...
这里hHandle是具体API的Handle。使用一个while循环來等待IsAPIReady的返回值,如果是true那么说明这个API已经注册了,可以跳出当前的while循环,执行后续的代码。如果返回false, 那么等待100毫秒继续查询动作,知道成功。
关于WaitForAPIReady:
来自MSDN的诠释:This function indicates whether the specified API set has been registered. This is a non-polling version of the IsAPIReady function. The IsAPIReady function, which polls, is deprecated.
DWORD WaitForAPIReady(
DWORD dwAPISlotIndex,
DWORD dwTimeout
);
Parameters
-
dwAPPISlotIndex
-
Index of the API slot to wait for.
-
dwTimeout
-
Timeout to wait for. Can be any value of milliseconds between zero and INFINITE.
它使用的是非轮询的方式,第一个参数是API的序号,第二个参数是Timeout的时间,单位是毫秒。当然在把第二个参数设置为0的时候,那等
待的时间就是0了,成为轮询方式。如果设置为INFINITE,则会在获得相应API 的index前,一直查询下去。
这两种方式都可以实现我们的目标。