Windows 使用WinAPI WlanQueryInterface-Delphi以编程方式查询频道号
在查询WlanQueryInterface以获取通道号时,请查看返回值是一个大整数,如1820789等。。有什么帮助吗Windows 使用WinAPI WlanQueryInterface-Delphi以编程方式查询频道号,windows,delphi,winapi,wifi,Windows,Delphi,Winapi,Wifi,在查询WlanQueryInterface以获取通道号时,请查看返回值是一个大整数,如1820789等。。有什么帮助吗 uses nduWlanTypes, nduWlanAPI; Function GetWifiChannelTest: String; var hClient: THandle; dwVersion: DWORD; ResultInt: DWORD; pInterface: Pndu_WLAN_INTERFACE_INFO_LIST; i: Integ
uses nduWlanTypes, nduWlanAPI;
Function GetWifiChannelTest: String;
var
hClient: THandle;
dwVersion: DWORD;
ResultInt: DWORD;
pInterface: Pndu_WLAN_INTERFACE_INFO_LIST;
i: Integer;
pInterfaceGuid: TGUID;
pdwDataSize: DWORD;
ppData: Tndu_WLAN_INTF_OPCODE;
pI: Pinteger;
p: pvoid;
begin
ResultInt := WlanOpenHandle(1, nil, @dwVersion, @hClient);
try
if ResultInt <> ERROR_SUCCESS then
begin
ShowMessage('Error Open CLient' + IntToStr(ResultInt));
Exit;
end;
ResultInt := WlanEnumInterfaces(hClient, nil, @pInterface);
if ResultInt <> ERROR_SUCCESS then
begin
ShowMessage('Error Enum Interfaces ' + IntToStr(ResultInt));
Exit;
end;
for i := 0 to pInterface^.dwNumberOfItems - 1 do
begin
pInterfaceGuid := pInterface^.InterfaceInfo[pInterface^.dwIndex]
.InterfaceGuid;
ResultInt := WlanQueryInterface(hClient, @pInterfaceGuid,
wlan_intf_opcode_channel_number, nil, @pdwDataSize, @ppData, nil);
try
if (ResultInt = ERROR_SUCCESS) and (pdwDataSize = SizeOf(ppData)) then
begin
p := @ppData;
pI := pvoid(p);
Result := IntToStr(pI^);
// the result is 1820789 ,but i need channel number like 10, or 11 etc...
end;
except
end;
end;
finally
WlanCloseHandle(hClient, nil);
end;
end;
您没有正确枚举接口。您不应该使用dwIndex作为InterfaceInfo[]数组的索引。使用循环计数器i代替 另外,您没有正确调用WlanQueryInterface。wlan_intf_操作码_信道_编号输出一个ULONG值,而不是wlan_intf_操作码值 此外,您正在泄漏WLanEnumenterFaces分配的WLAN接口信息列表 请尝试类似以下内容:
uses
nduWlanTypes, nduWlanAPI;
Function GetWifiChannelTest: String;
var
hClient: THandle;
dwVersion: DWORD;
ResultInt: DWORD;
pIntfList: PWLAN_INTERFACE_INFO_LIST;
i: DWORD;
IntfGuid: TGUID;
dwDataSize: DWORD;
ChannelNumber: ULONG;
begin
Result := '';
ResultInt := WlanOpenHandle(1, nil, @dwVersion, @hClient);
if ResultInt <> ERROR_SUCCESS then
begin
ShowMessage('Error Open Client: ' + IntToStr(ResultInt));
Exit;
end;
try
ResultInt := WlanEnumInterfaces(hClient, nil, @pIntfList);
if ResultInt <> ERROR_SUCCESS then
begin
ShowMessage('Error Enumerating Interfaces: ' + IntToStr(ResultInt));
Exit;
end;
try
for i := 0 to pIntfList^.dwNumberOfItems - 1 do
begin
IntfGuid := pIntfList^.InterfaceInfo[i].InterfaceGuid;
ResultInt := WlanQueryInterface(hClient, @IntfGuid, wlan_intf_opcode_channel_number, nil, @dwDataSize, @ChannelNumber, nil);
if ResultInt = ERROR_SUCCESS then
begin
Result := IntToStr(ChannelNumber);
Exit;
end;
end;
finally
WlanFreeMemory(pIntfList);
end;
finally
WlanCloseHandle(hClient, nil);
end;
end;
很难说。到处都是指针。例如,为什么要将指向某个Tndu_WLAN_INTF_操作码类型变量的指针而不是指向ULONG变量的指针传递给ppData参数?但还有更多。。我们甚至看不到API的翻译。嗨,请找到修改过的代码modified var ppData:pndu_WLAN_INTF_操作码;如果ResultInt=ERROR\u SUCCESS然后开始//现在结果是wlan\u intf\u操作码\u受支持的\u国家/地区\u字符串\u列表,但我需要通道号,如10或11等。。。结果1:=ppData^;//。wlan_intf_操作码_信道_编号;终止从上面的代码中我得到的结果是52388696,但是当我使用netsh wlan show接口时,reulst是11。谢谢pintflist:PWLAN\u接口\u信息\u列表;更改为pIntfList:Pndu\u WLAN\u接口\u信息\u列表;
uses
nduWlanTypes, nduWlanAPI;
Function GetWifiChannelTest: String;
var
hClient: THandle;
dwVersion: DWORD;
ResultInt: DWORD;
pIntfList: PWLAN_INTERFACE_INFO_LIST;
i: DWORD;
IntfGuid: TGUID;
dwDataSize: DWORD;
pChannelNumber: PULONG; // <--
begin
Result := '';
ResultInt := WlanOpenHandle(1, nil, @dwVersion, @hClient);
if ResultInt <> ERROR_SUCCESS then
begin
ShowMessage('Error Open Client: ' + IntToStr(ResultInt));
Exit;
end;
try
ResultInt := WlanEnumInterfaces(hClient, nil, @pIntfList);
if ResultInt <> ERROR_SUCCESS then
begin
ShowMessage('Error Enumerating Interfaces: ' + IntToStr(ResultInt));
Exit;
end;
try
for i := 0 to pIntfList^.dwNumberOfItems - 1 do
begin
IntfGuid := pIntfList^.InterfaceInfo[i].InterfaceGuid;
ResultInt := WlanQueryInterface(hClient, @IntfGuid, wlan_intf_opcode_channel_number, nil, @dwDataSize, @pChannelNumber, nil);
if ResultInt = ERROR_SUCCESS then
begin
Result := IntToStr(pChannelNumber^); // <--
Exit;
end;
end;
finally
WlanFreeMemory(pIntfList);
end;
finally
WlanCloseHandle(hClient, nil);
end;
end;