我需要使用 wlanapi 在C#
. 我可以关闭收音机但无法打开。这是我的代码:
WLAN_PHY_RADIO_STATE wlan_intf_opcode_radio_state = new WLAN_PHY_RADIO_STATE();
wlan_intf_opcode_radio_state.dwPhyIndex = 0; // TODO : can change ???
wlan_intf_opcode_radio_state.dot11HardwareRadioState = DOT11_RADIO_STATE.dot11_radio_state_on;// ignored in fact, according to http://msdn.microsoft.com/en-us/library/windows/desktop/ms706791(v=vs.85).aspx
wlan_intf_opcode_radio_state.dot11SoftwareRadioState = DOT11_RADIO_STATE.dot11_radio_state_on;
radioStatePtr = Marshal.AllocHGlobal(Marshal.SizeOf(wlan_intf_opcode_radio_state));
Marshal.StructureToPtr(wlan_intf_opcode_radio_state, radioStatePtr, false);
if (WlanEnumInterfaces(handle, IntPtr.Zero,
out ppInterfaceList) == ERROR_SUCCESS)
{
interfaceList = new WLAN_INTERFACE_INFO_LIST(ppInterfaceList);
for (int i = 0; i < interfaceList.dwNumberofItems; i++)
{
Guid pInterfaceGuid = ((WLAN_INTERFACE_INFO)interfaceList.InterfaceInfo[0]).InterfaceGuid;
if (WlanSetInterface(handle, ref pInterfaceGuid, WLAN_INTF_OPCODE.wlan_intf_opcode_radio_state, dataSize, ref ptr, IntPtr.Zero) == ERROR_SUCCESS)
MessageBox.Show("yes");
else MessageBox.Show("Some Issue");
}
}
定义 :
[DllImport("wlanapi.dll", SetLastError = true)]
public static extern uint WlanSetInterface(IntPtr hClientHandle, ref Guid pInterfaceGuid, WLAN_INTF_OPCODE OpCode, uint dwDataSize, ref IntPtr pData, IntPtr pReserved);
一切顺利我的意思是 wlansetinterface 功能返回ERROR_SUCCESS
,但收音机没有在我的 PC 中打开。请帮助我错过了什么?