public static extern uint WlanQueryInterface([In] IntPtr hClientHandle, [In] ref Guid pInterfaceGuid, WLAN_INTF_OPCODE OpCode, IntPtr pReserved, [Out] out uint pdwDataSize, ref IntPtr ppData, IntPtr pWlanOpcodeValueType);
private static extern uint WlanQueryInterface( IntPtr hClientHandle, [MarshalAs(UnmanagedType.LPStruct)] Guid pInterfaceGuid, WLAN_INTF_OPCODE OpCode, IntPtr pReserved, out uint pdwDataSize, ref IntPtr ppData, IntPtr pWlanOpcodeValueType);
public static extern uint WlanSetInterface(IntPtr hClientHandle, ref Guid pInterfaceGuid, WLAN_INTF_OPCODE OpCode, uint dwDataSize, ref object obj, IntPtr pReserved);
/// <summary> /// Gets a parameter of the interface whose data type is <see cref="int"/>. /// /// Possible Win32 errors: /// ERROR_ACCESS_DENIED: The caller does not have sufficient permissions to perform the requested operation. /// ERROR_INVALID PARAMETER: hClientHandle is NULL or invalid, pInterfaceGuid is NULL, pReserved is not NULL, ppData is NULL, or pdwDataSize is NULL. /// ERROR_INVALID_HANDLE: The handle hClientHandle was not found in the handle table. /// ERROR_INVALID_STATE: OpCode is set to wlan_intf_opcode_current_connection and the client is not currently connected to a network. /// ERROR_NOT_ENOUGH_MEMORY: Failed to allocate memory for the query results. /// RPC_STATUS: Various error codes. /// </summary> /// <param name="clientHandle">The client's session handle, obtained by a previous call to the WlanOpenHandle function.</param> /// <param name="interfaceId">The GUID of the interface to be queried.</param> /// <param name="wlanIntfOpcode">A WLAN_INTF_OPCODE value that specifies the parameter to be queried.</param> /// <returns>The integer value.</returns> public static int GetInterfaceInt(SafeClientHandle clientHandle, Guid interfaceId, WLAN_INTF_OPCODE wlanIntfOpcode) { var queryData = IntPtr.Zero; try { var result = WlanQueryInterface( clientHandle, interfaceId, wlanIntfOpcode, IntPtr.Zero, out uint dataSize, out queryData, out WLAN_OPCODE_VALUE_TYPE opcodeValueType); // ERROR_INVALID_STATE will be returned if the client is not connected to a network. return(CheckResult(nameof(GetInterfaceInt), result, false) ? Marshal.ReadInt32(queryData) : -1); } finally { if (queryData != IntPtr.Zero) { WlanFreeMemory(queryData); } } }
private static bool SetInterfaceInt(SafeClientHandle clientHandle, Guid interfaceId, WLAN_INTF_OPCODE wlanIntfOpcode, int value) { var setData = IntPtr.Zero; try { setData = Marshal.AllocHGlobal(sizeof(int)); Marshal.WriteInt32(setData, value); var result = WlanSetInterface( clientHandle, interfaceId, wlanIntfOpcode, sizeof(int), setData, IntPtr.Zero); return(CheckResult(nameof(WlanSetInterface), result, false)); } finally { Marshal.FreeHGlobal(setData); } }
private static int?GetInterfaceInt(SafeClientHandle clientHandle, Guid interfaceId, WLAN_INTF_OPCODE wlanIntfOpcode) { var queryData = IntPtr.Zero; try { var result = WlanQueryInterface( clientHandle, interfaceId, wlanIntfOpcode, IntPtr.Zero, out _, out queryData, IntPtr.Zero); return(CheckResult(nameof(WlanQueryInterface), result, false) ? Marshal.ReadInt32(queryData) : (int?)null); } finally { if (queryData != IntPtr.Zero) { WlanFreeMemory(queryData); } } }