服务终止

问题描述:

我有一个Windows服务,可以进行一些网络操作,比如访问WiFi。该服务必须经常调用WlanOpenHandle()API,有时服务终止,我怀疑它是围绕WlanOpenHandle()。每次调用API时,WlanCloseHandle()都会关闭
。服务有时会终止。 API有这样的问题吗?

I have a Windows service that does some network operation like accessing WiFi. The service has to call WlanOpenHandle() API frequently and sometimes the service terminates which I suspect is around WlanOpenHandle(). Every time the API is called, it is closed by WlanCloseHandle(). Still the service is terminated sometimes. Is there any such issues with the API?

您好,¥b $ b

Hello,

感谢您在此发布。

Thanks for posting here.

>>我有一项Windows服务可以进行一些网络操作,例如访问WiFi。该服务必须经常调用WlanOpenHandle()API,有时服务终止,我怀疑它是围绕WlanOpenHandle()。每次API调用
时,它都会被WlanCloseHandle()关闭。服务有时会终止。 API有这样的问题吗?


>>I have a Windows service that does some network operation like accessing WiFi. The service has to call WlanOpenHandle() API frequently and sometimes the service terminates which I suspect is around WlanOpenHandle(). Every time the API is called, it is closed by WlanCloseHandle(). Still the service is terminated sometimes. Is there any such issues with the API?

你得到了什么错误?您可以检查WlanOpenHandle的返回值,也可以通过GetLastError获取更详细的错误信息。

What error did you get? You could check the return value of the WlanOpenHandle, you could also get more detailed error information by the GetLastError.

您的服务版本是什么? dwClientVersion和pdwNegotiatedVersion指定的版本号是由主要版本和次要版本组成的复合版本号。主要版本由低位字指定,次要版本是由高位字指定的
。 不太确定如何使用WlanOpenHandle函数。它经常被这样使用:

What's your service version is? The version number specified by dwClientVersion and pdwNegotiatedVersion is a composite version number made up of both major and minor versions. The major version is specified by the low-order word, and the minor version is specified by the high-order word. Not very sure how do you use the WlanOpenHandle function. it is often used like this:

DWORD dwError = 0;
DWORD dwServiceVersion = 0;
HANDLE hClient = NULL;

dwError = WlanOpenHandle(
    WLAN_API_VERSION,   
    NULL,               // reserved
    &dwServiceVersion,
    &hClient
    )

if (ERROR_SUCCESS != dwError)
{
    return -1;
}

// check service version
if (WLAN_API_VERSION_MAJOR(dwServiceVersion) < WLAN_API_VERSION_MAJOR(WLAN_API_VERSION_2_0))
{
    WlanCloseHandle(hClient, NULL);
}

带有SP3的Windows XP和适用于Windows XP SP2的无线LAN API: 如果无线零配置(WZC)服务尚未启动或WZC服务没有响应,WlanOpenHandle将返回错误消息。

Windows XP with SP3 and Wireless LAN API for Windows XP with SP2:  WlanOpenHandle will return an error message if the Wireless Zero Configuration (WZC) service has not been started or if the WZC service is not responsive.

祝福,

Best Wishes,

杰克

Jack