private static bool SetRadioState(Guid interfaceGuid, Wlan.Dot11RadioState radioState) { //set Wlan.WlanPhyRadioState struct state's value. var state = new Wlan.WlanPhyRadioState { dwPhyIndex = (int)Wlan.Dot11PhyType.Any, dot11SoftwareRadioState = radioState, }; var size = Marshal.SizeOf(state); var pointer = IntPtr.Zero; try { pointer = Marshal.AllocHGlobal(size); Marshal.StructureToPtr(state, pointer, false); var clientHandle = IntPtr.Zero; try { uint negotiatedVersion; var result = Wlan.WlanOpenHandle( Wlan.WLAN_CLIENT_VERSION_LONGHORN, IntPtr.Zero, out negotiatedVersion, out clientHandle); if (result != 0) { return(false); } result = Wlan.WlanSetInterface( clientHandle, interfaceGuid, Wlan.WlanIntfOpcode.RadioState, (uint)size, pointer, IntPtr.Zero); return(result == 0); } finally { Wlan.WlanCloseHandle( clientHandle, IntPtr.Zero); } } finally { Marshal.FreeHGlobal(pointer); } }
/// <summary> /// Sets a parameter of the interface whose data type is <see cref="int"/>. /// </summary> /// <param name="opCode">The opcode of the parameter.</param> /// <param name="value">The value to set.</param> private void SetInterfaceInt(Wlan.WlanIntfOpcode opCode, int value) { IntPtr valuePtr = Marshal.AllocHGlobal(sizeof(int)); Marshal.WriteInt32(valuePtr, value); try { Wlan.ThrowIfError( Wlan.WlanSetInterface(client.clientHandle, info.interfaceGuid, opCode, sizeof(int), valuePtr, IntPtr.Zero)); } finally { Marshal.FreeHGlobal(valuePtr); } }