IsAPIReady和WaitForAPIReady

关于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:
hAPI

[in] Handle to the specified API set.

由于它是使用查询式的工作方式,而我是希望在某一个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前,一直查询下去。
这两种方式都可以实现我们的目标。





 

 


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值