为什么Windows WiFi API的’WlanEnumInterfaces’在出现’ERROR_INVALID_STATE’时失败?

huangapple go评论62阅读模式
英文:

Why windows wifi API 'WlanEnumInterfaces' is failed with 'ERROR_INVALID_STATE'?

问题

以下是代码的中文翻译部分:

我正在尝试使用Windows API枚举WiFi网络,但我不知道为什么会出现错误代码ERROR_INVALID_STATE。以下是我的示例代码:

PWLAN_INTERFACE_INFO_LIST pIfList = NULL;

DWORD dwNegotiatedVersion;
HANDLE hClientHandle;
DWORD Res = WFDOpenHandle(WFD_API_VERSION, &dwNegotiatedVersion, &hClientHandle);
if (Res != ERROR_SUCCESS)
{
    WFDCloseHandle(hClientHandle);
    return;
}
Res = WlanEnumInterfaces(hClientHandle, NULL, &pIfList);
if (Res == ERROR_INVALID_STATE)
{
    WlanCloseHandle(hClientHandle, NULL);
    return;
}
else if (Res != ERROR_SUCCESS)
{
    WlanCloseHandle(hClientHandle, NULL);
    return;
}

我正在使用Windows 10,并使用Visual Studio 2015进行调试。

英文:

I am trying to enumerate the WiFi networks with windows API. But I don't know why it fails with the error code ERROR_INVALID_STATE . Below is my sample code

PWLAN_INTERFACE_INFO_LIST  pIfList = NULL;
	
	DWORD dwNegotiatedVersion;
	HANDLE hClientHandle;
	DWORD Res=WFDOpenHandle(WFD_API_VERSION, &dwNegotiatedVersion, &hClientHandle);
	if (Res != ERROR_SUCCESS)
	{
		WFDCloseHandle(hClientHandle);
		return;
	}
	Res = WlanEnumInterfaces(hClientHandle, NULL, &pIfList);
	if (Res == ERROR_INVALID_STATE)
	{
		WlanCloseHandle(hClientHandle, NULL);
		return;
	}
	else if (Res != ERROR_SUCCESS) 
	{
		WlanCloseHandle(hClientHandle, NULL);
		return;
	}

I am using Windows 10.and debugging using visual studio 2015

答案1

得分: 2

WlanEnumInterfaces 中的句柄是从 WlanOpenHandle 获得的句柄,如文档所述。它不是来自 WFDOpenHandle 的 WFD 句柄。

英文:

The handle for WlanEnumInterfaces is a handle from WlanOpenHandle - as stated in the documentation. It is not a WFD handle from WFDOpenHandle.

huangapple
  • 本文由 发表于 2023年3月31日 23:26:45
  • 转载请务必保留本文链接:https://go.coder-hub.com/75900233.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定