diff --git a/PInvoke/WlanApi/Adhoc.cs b/PInvoke/WlanApi/Adhoc.cs
new file mode 100644
index 00000000..9606eee8
--- /dev/null
+++ b/PInvoke/WlanApi/Adhoc.cs
@@ -0,0 +1,1095 @@
+using System;
+using System.Runtime.InteropServices;
+using Vanara.Collections;
+using Vanara.InteropServices;
+
+namespace Vanara.PInvoke
+{
+ public static partial class WlanApi
+ {
+ /// Specifies the authentication algorithm for user or machine authentication on an ad hoc network.
+ [PInvokeData("adhoc.h")]
+ public enum DOT11_ADHOC_AUTH_ALGORITHM
+ {
+ /// The authentication algorithm specified is invalid.
+ DOT11_ADHOC_AUTH_ALGO_INVALID = -1,
+
+ /// Specifies an IEEE 802.11 Open System authentication algorithm.
+ DOT11_ADHOC_AUTH_ALGO_80211_OPEN = 1,
+
+ ///
+ /// Specifies an IEEE 802.11i Robust Security Network Association (RSNA) algorithm that uses the pre-shared key (PSK) mode. IEEE
+ /// 802.1X port authorization is performed by the supplicant and authenticator. Cipher keys are dynamically derived through a
+ /// pre-shared key that is used on both the supplicant and authenticator.
+ ///
+ DOT11_ADHOC_AUTH_ALGO_RSNA_PSK = 7
+ }
+
+ /// Specifies a cipher algorithm used to encrypt and decrypt information on an ad hoc network.
+ [PInvokeData("adhoc.h")]
+ public enum DOT11_ADHOC_CIPHER_ALGORITHM
+ {
+ /// The cipher algorithm specified is invalid.
+ DOT11_ADHOC_CIPHER_ALGO_INVALID = -1,
+
+ /// Specifies that no cipher algorithm is enabled or supported.
+ DOT11_ADHOC_CIPHER_ALGO_NONE = 0x00,
+
+ ///
+ /// Specifies a Counter Mode with Cipher Block Chaining Message Authentication Code Protocol (CCMP) algorithm. The CCMP
+ /// algorithm is specified in the IEEE 802.11i-2004 standard and RFC 3610. CCMP is used with the Advanced Encryption Standard
+ /// (AES) encryption algorithm, as defined in FIPS PUB 197.
+ ///
+ DOT11_ADHOC_CIPHER_ALGO_CCMP = 0x04,
+
+ /// Specifies a Wired Equivalent Privacy (WEP) algorithm of any length.
+ DOT11_ADHOC_CIPHER_ALGO_WEP = 0x101,
+ }
+
+ /// Specifies the reason why a connection attempt failed.
+ [PInvokeData("adhoc.h")]
+ public enum DOT11_ADHOC_CONNECT_FAIL_REASON
+ {
+ ///
+ /// The local host's configuration is incompatible with the target network. This occurs when the local host is 802.11d compliant
+ /// and the regulatory domain of the local host is not compatible with the regulatory domain of the target network. For more
+ /// information about regulatory domains, see the IEEE 802.11d-2001 standard. The standard can be downloaded from the IEEE website.
+ ///
+ DOT11_ADHOC_CONNECT_FAIL_DOMAIN_MISMATCH = 0,
+
+ /// The passphrase supplied to authenticate the local machine or user on the target network is incorrect.
+ DOT11_ADHOC_CONNECT_FAIL_PASSPHRASE_MISMATCH = 1,
+
+ /// The connection failed for another reason.
+ DOT11_ADHOC_CONNECT_FAIL_OTHER = 2
+ }
+
+ /// Specifies the connection state of an ad hoc network.
+ [PInvokeData("adhoc.h")]
+ public enum DOT11_ADHOC_NETWORK_CONNECTION_STATUS
+ {
+ /// The connection status cannot be determined. A network with this status should not be used.
+ DOT11_ADHOC_NETWORK_CONNECTION_STATUS_INVALID = 0,
+
+ ///
+ /// There are no hosts or clients connected to the network. There are also no pending connection requests for this network.
+ ///
+ DOT11_ADHOC_NETWORK_CONNECTION_STATUS_DISCONNECTED = 11,
+
+ ///
+ /// There is an outstanding connection request. Once the client or host succeeds or fails in its connection attempt, the
+ /// connection status is updated.
+ ///
+ DOT11_ADHOC_NETWORK_CONNECTION_STATUS_CONNECTING = 12,
+
+ /// A client or host is connected to the network.
+ DOT11_ADHOC_NETWORK_CONNECTION_STATUS_CONNECTED = 13,
+
+ /// The network has been formed. Once a client or host connects to the network, the connection status is updated.
+ DOT11_ADHOC_NETWORK_CONNECTION_STATUS_FORMED = 14
+ }
+
+ ///
+ /// Represents a wireless network interface card (NIC).
+ ///
+ /// Note Ad hoc mode might not be available in future versions of Windows. Starting with Windows 8.1 and Windows Server 2012
+ /// R2, use Wi-Fi Direct instead.
+ ///
+ ///
+ // https://docs.microsoft.com/en-us/windows/win32/api/adhoc/nn-adhoc-idot11adhocinterface
+ [PInvokeData("adhoc.h", MSDNShortId = "NN:adhoc.IDot11AdHocInterface")]
+ [ComImport, Guid("8F10CC2B-CF0D-42a0-ACBE-E2DE7007384D"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
+ public interface IDot11AdHocInterface
+ {
+ ///
+ /// Gets the signature of the NIC. This signature is stored in the registry and it is used by TCP/IP to uniquely identify the NIC.
+ ///
+ /// The signature of the NIC.
+ // https://docs.microsoft.com/en-us/windows/win32/api/adhoc/nf-adhoc-idot11adhocinterface-getdevicesignature HRESULT
+ // GetDeviceSignature( GUID *pSignature );
+ Guid GetDeviceSignature();
+
+ /// Gets the friendly name of the NIC.
+ ///
+ /// The friendly name of the NIC. The SSID of the network is used as the friendly name.
+ /// You must free this string using CoTaskMemFree.
+ ///
+ // https://docs.microsoft.com/en-us/windows/win32/api/adhoc/nf-adhoc-idot11adhocinterface-getfriendlyname HRESULT
+ // GetFriendlyName( LPWSTR *ppszName );
+ [return: MarshalAs(UnmanagedType.LPWStr)]
+ string GetFriendlyName();
+
+ /// Specifies whether the NIC is 802.11d compliant.
+ ///
+ /// A pointer to a boolean that specifies 802.11d compliance. The boolean value is set to TRUE if the NIC is compliant
+ /// and FALSE otherwise.
+ ///
+ // https://docs.microsoft.com/en-us/windows/win32/api/adhoc/nf-adhoc-idot11adhocinterface-isdot11d HRESULT IsDot11d( BOOLEAN
+ // *pf11d );
+ [return: MarshalAs(UnmanagedType.U1)]
+ bool IsDot11d();
+
+ /// Specifies whether a NIC supports the creation or use of an ad hoc network.
+ ///
+ /// A pointer to a boolean that specifies the NIC's ad hoc network capabilities. The boolean value is set to TRUE if the
+ /// NIC supports the creation and use of ad hoc networks and FALSE otherwise.
+ ///
+ ///
+ /// pfAdHocCapable can be set to FALSE for many reasons, including the following:
+ ///
+ /// -
+ /// Group policy prohibits the use of ad hoc networks on this interface
+ ///
+ /// -
+ ///
+ /// The machine is configured to only connect to infrastructure networks, or the machine configuration disallows wireless connections
+ ///
+ ///
+ /// -
+ /// The NIC does not support ad hoc networks
+ ///
+ ///
+ ///
+ // https://docs.microsoft.com/en-us/windows/win32/api/adhoc/nf-adhoc-idot11adhocinterface-isadhoccapable HRESULT IsAdHocCapable(
+ // BOOLEAN *pfAdHocCapable );
+ [return: MarshalAs(UnmanagedType.U1)]
+ bool IsAdHocCapable();
+
+ /// Specifies whether the radio is on.
+ /// A pointer to a boolean that specifies the radio state. The value is set to TRUE if the radio is on.
+ // https://docs.microsoft.com/en-us/windows/win32/api/adhoc/nf-adhoc-idot11adhocinterface-isradioon HRESULT IsRadioOn( BOOLEAN
+ // *pfIsRadioOn );
+ [return: MarshalAs(UnmanagedType.U1)]
+ bool IsRadioOn();
+
+ /// Gets the network that is currently active on the interface.
+ /// A pointer to an IDot11AdHocNetwork object that represents the active network.
+ // https://docs.microsoft.com/en-us/windows/win32/api/adhoc/nf-adhoc-idot11adhocinterface-getactivenetwork HRESULT
+ // GetActiveNetwork( IDot11AdHocNetwork **ppNetwork );
+ IDot11AdHocNetwork GetActiveNetwork();
+
+ /// Gets the collection of security settings associated with this NIC.
+ /// A pointer to an IEnumDot11AdHocSecuritySettings interface that contains the collection of security settings.
+ // https://docs.microsoft.com/en-us/windows/win32/api/adhoc/nf-adhoc-idot11adhocinterface-getienumsecuritysettings HRESULT
+ // GetIEnumSecuritySettings( IEnumDot11AdHocSecuritySettings **ppEnum );
+ IEnumDot11AdHocSecuritySettings GetIEnumSecuritySettings();
+
+ /// Gets the collection of networks associated with this NIC.
+ ///
+ /// An optional parameter that specifies the GUID of the application that created the network. An application can use this
+ /// identifier to limit the networks enumerated to networks created by the application. For this filtering to work correctly,
+ /// all instances of the application on all machines must use the same GUID.
+ ///
+ /// A pointer to a IEnumDot11AdHocNetworks interface that contains the enumerated networks.
+ // https://docs.microsoft.com/en-us/windows/win32/api/adhoc/nf-adhoc-idot11adhocinterface-getienumdot11adhocnetworks HRESULT
+ // GetIEnumDot11AdHocNetworks( GUID *pFilterGuid, IEnumDot11AdHocNetworks **ppEnum );
+ IEnumDot11AdHocNetworks GetIEnumDot11AdHocNetworks([In, Optional] GuidPtr pFilterGuid);
+
+ ///
+ /// Gets the connection status of the active network associated with this NIC. You can determine the active network by calling IDot11AdHocInterface::GetActiveNetwork.
+ ///
+ /// A pointer to a DOT11_ADHOC_NETWORK_CONNECTION_STATUS value that specifies the connection state.
+ // https://docs.microsoft.com/en-us/windows/win32/api/adhoc/nf-adhoc-idot11adhocinterface-getstatus HRESULT GetStatus(
+ // DOT11_ADHOC_NETWORK_CONNECTION_STATUS *pState );
+ DOT11_ADHOC_NETWORK_CONNECTION_STATUS GetStatus();
+ }
+
+ ///
+ ///
+ /// The IDot11AdHocInterfaceNotificationSink interface defines the notifications supported by IDot11AdHocInterface. To
+ /// register for notifications, call the Advise method on an instantiated IDot11AdHocManager object with the
+ /// IDot11AdHocInterfaceNotificationSink interface passed as the pUnk parameter. To terminate notifications, call the
+ /// Unadvise method.
+ ///
+ ///
+ /// Note Ad hoc mode might not be available in future versions of Windows. Starting with Windows 8.1 and Windows Server 2012
+ /// R2, use Wi-Fi Direct instead.
+ ///
+ ///
+ // https://docs.microsoft.com/en-us/windows/win32/api/adhoc/nn-adhoc-idot11adhocinterfacenotificationsink
+ [PInvokeData("adhoc.h", MSDNShortId = "NN:adhoc.IDot11AdHocInterfaceNotificationSink")]
+ [ComImport, Guid("8F10CC2F-CF0D-42a0-ACBE-E2DE7007384D"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
+ public interface IDot11AdHocInterfaceNotificationSink
+ {
+ /// Notifies the client that the connection status of the network associated with the NIC has changed.
+ /// A pointer to a DOT11_ADHOC_NETWORK_CONNECTION_STATUS value that specifies the new connection state.
+ ///
+ /// Possible return values include, but are not limited to, the following.
+ ///
+ ///
+ /// Return code
+ /// Description
+ ///
+ /// -
+ /// S_OK
+ /// The method completed successfully.
+ ///
+ /// -
+ /// E_FAIL
+ /// The method failed.
+ ///
+ ///
+ ///
+ ///
+ /// This notification is triggered when the connection status changes as a result of connection and disconnection requests
+ /// issued by the current application. It is also triggered when other applications issue successful connection and
+ /// disconnection requests using the IDot11AdHocNetwork methods or the Native Wifi functions.
+ ///
+ // https://docs.microsoft.com/en-us/windows/win32/api/adhoc/nf-adhoc-idot11adhocinterfacenotificationsink-onconnectionstatuschange
+ // HRESULT OnConnectionStatusChange( DOT11_ADHOC_NETWORK_CONNECTION_STATUS eStatus );
+ [PreserveSig]
+ HRESULT OnConnectionStatusChange(DOT11_ADHOC_NETWORK_CONNECTION_STATUS eStatus);
+ }
+
+ ///
+ ///
+ /// The IDot11AdHocManager interface creates and manages 802.11 ad hoc networks. It is the top-level 802.11 ad hoc interface
+ /// and the only ad hoc interface with a coclass. As such, it is the only ad hoc interface that can be instantiated by CoCreateInstance.
+ ///
+ ///
+ /// Note Ad hoc mode might not be available in future versions of Windows. Starting with Windows 8.1 and Windows Server 2012
+ /// R2, use Wi-Fi Direct instead.
+ ///
+ ///
+ /// The IDot11AdHocManager coclass implements the IConnectionPoint interface. The Advise method can be used to register for
+ /// network manager, network, and interface-related notifications. Notifications are implemented by the
+ /// IDot11AdHocManagerNotificationSink interface. To register for notifications, call the Advise method with the appropriate
+ /// notification sink interface as the pUnk parameter.
+ ///
+ ///
+ // https://docs.microsoft.com/en-us/windows/win32/api/adhoc/nn-adhoc-idot11adhocmanager
+ [PInvokeData("adhoc.h", MSDNShortId = "NN:adhoc.IDot11AdHocManager")]
+ [ComImport, Guid("8F10CC26-CF0D-42a0-ACBE-E2DE7007384D"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown), CoClass(typeof(Dot11AdHocManager))]
+ public interface IDot11AdHocManager
+ {
+ /// Creates a wireless ad hoc network. Other clients and hosts can connect to this network.
+ ///
+ /// The friendly name of the network. This string should be limited to 32 characters. The SSID should be used as the friendly
+ /// name. This name is broadcasted in a beacon.
+ ///
+ ///
+ /// The password used for machine or user authentication on the network.
+ ///
+ /// The length of the password string depends on the security settings passed in the pSecurity parameter. The following table
+ /// shows the password length associated with various security settings.
+ ///
+ ///
+ ///
+ /// Security Settings
+ /// Password Length
+ ///
+ /// -
+ /// Open-None
+ /// 0
+ ///
+ /// -
+ /// Open-WEP
+ /// 5 or 13 characters; 10 or 26 hexadecimal digits
+ ///
+ /// -
+ /// WPA2PSK
+ /// 8 to 63 characters
+ ///
+ ///
+ ///
+ /// For the enumerated values that correspond to the security settings pair above, see DOT11_ADHOC_AUTH_ALGORITHM and DOT11_ADHOC_CIPHER_ALGORITHM
+ ///
+ ///
+ ///
+ ///
+ /// The geographical location in which the network will be created. For a list of possible values, see Table of Geographical Locations.
+ ///
+ ///
+ /// If the interface is not 802.11d conformant, this value is ignored. That means if IDot11AdHocInterface::IsDot11d returns
+ /// FALSE, this value is ignored.
+ ///
+ ///
+ /// If you are not sure which value to use, set GeographicalId to CTRY_DEFAULT. If you use CTRY_DEFAULT, 802.11d conformance is
+ /// not enforced.
+ ///
+ ///
+ ///
+ /// An optional pointer to an IDot11AdHocInterface that specifies the network interface upon which the new network is created.
+ /// If this parameter is NULL, the first unused interface is used. If all interfaces are in use, the first enumerated
+ /// interface is used. In that case, the previous network on the interface is disconnected.
+ ///
+ ///
+ /// A pointer to an IDot11AdHocSecuritySettings interface that specifies the security settings used on the network.
+ ///
+ ///
+ /// An optional parameter that specifies the GUID of the application that created the network. An application can use this
+ /// identifier to limit the networks enumerated by GetIEnumDot11AdHocNetworks to networks created by the application. For this
+ /// filtering to work correctly, all instances of the application on all machines must use the same GUID.
+ ///
+ /// A pointer to an IDot11AdHocNetwork interface that represents the created network.
+ ///
+ ///
+ /// After a successful CreateNetwork call, the network object returned by pIAdHoc is provisioned but not constructed. A
+ /// subsequent call to CommitCreatedNetwork initializes the network. Beacons are not sent until the network is committed.
+ ///
+ ///
+ /// There are no clients or hosts connected to the network after a CreateNetwork call. Applications are notified of both
+ /// successful and failed connection attempts using the IDot11AdHocManagerNotificationSink interface. For information about
+ /// registering for notifications on that interface, see IDot11AdHocManager.
+ ///
+ ///
+ // https://docs.microsoft.com/en-us/windows/win32/api/adhoc/nf-adhoc-idot11adhocmanager-createnetwork HRESULT CreateNetwork(
+ // LPCWSTR Name, LPCWSTR Password, LONG GeographicalId, IDot11AdHocInterface *pInterface, IDot11AdHocSecuritySettings
+ // *pSecurity, GUID *pContextGuid, IDot11AdHocNetwork **pIAdHoc );
+ IDot11AdHocNetwork CreateNetwork([MarshalAs(UnmanagedType.LPWStr)] string Name, [MarshalAs(UnmanagedType.LPWStr)] string Password,
+ int GeographicalId, [In, Optional] IDot11AdHocInterface pInterface, IDot11AdHocSecuritySettings pSecurity, [In, Optional] GuidPtr pContextGuid);
+
+ ///
+ /// Initializes a created network and optionally commits the network's profile to the profile store. The network must be created
+ /// using CreateNetwork before calling CommitCreatedNetwork.
+ ///
+ /// A pointer to a IDot11AdHocNetwork interface that specifies the network to be initialized and committed.
+ ///
+ ///
+ /// An optional parameter that specifies whether a wireless profile should be saved. If TRUE, the profile is saved to the
+ /// profile store. Once a profile has been saved, the user can modify the profile using the Manage Wireless Network user
+ /// interface. Profiles can also be modified using the Native Wifi Functions.
+ ///
+ /// Saving a profile modifies the network signature returned by IDot11AdHocNetwork::GetSignature.
+ ///
+ ///
+ ///
+ /// An optional parameter that specifies whether the profile to be saved is an all-user profile. If set to TRUE, the
+ /// profile is specific to the current user. If set to FALSE, the profile is an all-user profile and can be used by any
+ /// user logged into the machine. This parameter is ignored if fSaveProfile is FALSE.
+ ///
+ ///
+ /// By default, only members of the Administrators group can persist an all-user profile. These security settings can be altered
+ /// using the WlanSetSecuritySettings function. Your application must be launched by a user with sufficient privileges for an
+ /// all-user profile to be persisted successfully.
+ ///
+ ///
+ /// If your application is running in a Remote Desktop window, you can only save an all-user profile. User-specific profiles
+ /// cannot be saved from an application running remotely.
+ ///
+ ///
+ // https://docs.microsoft.com/en-us/windows/win32/api/adhoc/nf-adhoc-idot11adhocmanager-commitcreatednetwork HRESULT
+ // CommitCreatedNetwork( IDot11AdHocNetwork *pIAdHoc, BOOLEAN fSaveProfile, BOOLEAN fMakeSavedProfileUserSpecific );
+ void CommitCreatedNetwork(IDot11AdHocNetwork pIAdHoc, [MarshalAs(UnmanagedType.U1)] bool fSaveProfile, [MarshalAs(UnmanagedType.U1)] bool fMakeSavedProfileUserSpecific);
+
+ /// Returns a list of available ad hoc network destinations within connection range. This list may be filtered.
+ ///
+ /// An optional parameter that specifies the GUID of the application that created the network. An application can use this
+ /// identifier to limit the networks enumerated to networks created by the application. For this filtering to work correctly,
+ /// all instances of the application on all machines must use the same GUID.
+ ///
+ /// A pointer to an IEnumDot11AdHocNetworks interface that contains the enumerated networks.
+ // https://docs.microsoft.com/en-us/windows/win32/api/adhoc/nf-adhoc-idot11adhocmanager-getienumdot11adhocnetworks HRESULT
+ // GetIEnumDot11AdHocNetworks( GUID *pContextGuid, IEnumDot11AdHocNetworks **ppEnum );
+ IEnumDot11AdHocNetworks GetIEnumDot11AdHocNetworks([In, Optional] GuidPtr pContextGuid);
+
+ /// Returns the set of wireless network interface cards (NICs) available on the machine.
+ /// A pointer to an IEnumDot11AdHocInterfaces interface that contains the list of NICs.
+ // https://docs.microsoft.com/en-us/windows/win32/api/adhoc/nf-adhoc-idot11adhocmanager-getienumdot11adhocinterfaces HRESULT
+ // GetIEnumDot11AdHocInterfaces( IEnumDot11AdHocInterfaces **ppEnum );
+ IEnumDot11AdHocInterfaces GetIEnumDot11AdHocInterfaces();
+
+ /// Returns the network associated with a signature.
+ ///
+ /// A signature that uniquely identifies an ad hoc network. This signature is generated from certain network attributes.
+ ///
+ /// A pointer to an IDot11AdHocNetwork interface that represents the network associated with the signature.
+ // https://docs.microsoft.com/en-us/windows/win32/api/adhoc/nf-adhoc-idot11adhocmanager-getnetwork HRESULT GetNetwork( GUID
+ // *NetworkSignature, IDot11AdHocNetwork **pNetwork );
+ IDot11AdHocNetwork GetNetwork(in Guid NetworkSignature);
+ }
+
+ ///
+ ///
+ /// The IDot11AdHocManagerNotificationSink interface defines the notifications supported by the IDot11AdHocManager interface.
+ /// To register for notifications, call the Advise method on an instantiated IDot11AdHocManager object with the
+ /// IDot11AdHocManagerNotificationSink interface passed as the pUnk parameter. To terminate notifications, call the Unadvise method.
+ ///
+ ///
+ /// Note Ad hoc mode might not be available in future versions of Windows. Starting with Windows 8.1 and Windows Server 2012
+ /// R2, use Wi-Fi Direct instead.
+ ///
+ ///
+ // https://docs.microsoft.com/en-us/windows/win32/api/adhoc/nn-adhoc-idot11adhocmanagernotificationsink
+ [PInvokeData("adhoc.h", MSDNShortId = "NN:adhoc.IDot11AdHocManagerNotificationSink")]
+ [ComImport, Guid("8F10CC27-CF0D-42a0-ACBE-E2DE7007384D"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
+ public interface IDot11AdHocManagerNotificationSink
+ {
+ /// Notifies the client that a new wireless ad hoc network destination is in range and available for connection.
+ /// A pointer to an IDot11AdHocNetwork interface that represents the new network.
+ ///
+ /// Possible return values include, but are not limited to, the following.
+ ///
+ ///
+ /// Return code
+ /// Description
+ ///
+ /// -
+ /// S_OK
+ /// The method completed successfully.
+ ///
+ /// -
+ /// E_FAIL
+ /// The method failed.
+ ///
+ ///
+ ///
+ // https://docs.microsoft.com/en-us/windows/win32/api/adhoc/nf-adhoc-idot11adhocmanagernotificationsink-onnetworkadd HRESULT
+ // OnNetworkAdd( IDot11AdHocNetwork *pIAdHocNetwork );
+ [PreserveSig]
+ HRESULT OnNetworkAdd(IDot11AdHocNetwork pIAdHocNetwork);
+
+ /// Notifies the client that a wireless ad hoc network destination is no longer available for connection.
+ ///
+ /// A pointer to a signature that uniquely identifies the newly unavailable network. For more information about signatures, see IDot11AdHocNetwork::GetSignature.
+ ///
+ ///
+ /// Possible return values include, but are not limited to, the following.
+ ///
+ ///
+ /// Return code
+ /// Description
+ ///
+ /// -
+ /// S_OK
+ /// The method completed successfully.
+ ///
+ /// -
+ /// E_FAIL
+ /// The method failed.
+ ///
+ ///
+ ///
+ // https://docs.microsoft.com/en-us/windows/win32/api/adhoc/nf-adhoc-idot11adhocmanagernotificationsink-onnetworkremove HRESULT
+ // OnNetworkRemove( GUID *Signature );
+ [PreserveSig]
+ HRESULT OnNetworkRemove(in Guid Signature);
+
+ /// Notifies the client that a new network interface card (NIC) is active.
+ /// A pointer to an IDot11AdHocInterface interface that represents the activated NIC.
+ ///
+ /// Possible return values include, but are not limited to, the following.
+ ///
+ ///
+ /// Return code
+ /// Description
+ ///
+ /// -
+ /// S_OK
+ /// The method completed successfully.
+ ///
+ /// -
+ /// E_FAIL
+ /// The method failed.
+ ///
+ ///
+ ///
+ // https://docs.microsoft.com/en-us/windows/win32/api/adhoc/nf-adhoc-idot11adhocmanagernotificationsink-oninterfaceadd HRESULT
+ // OnInterfaceAdd( IDot11AdHocInterface *pIAdHocInterface );
+ [PreserveSig]
+ HRESULT OnInterfaceAdd(IDot11AdHocInterface pIAdHocInterface);
+
+ /// Notifies the client that a network interface card (NIC) has become inactive.
+ ///
+ /// A pointer to a signature that uniquely identifies the inactive NIC. For more information about signatures, see IDot11AdHocInterface::GetDeviceSignature.
+ ///
+ ///
+ /// Possible return values include, but are not limited to, the following.
+ ///
+ ///
+ /// Return code
+ /// Description
+ ///
+ /// -
+ /// S_OK
+ /// The method completed successfully.
+ ///
+ /// -
+ /// E_FAIL
+ /// The method failed.
+ ///
+ ///
+ ///
+ // https://docs.microsoft.com/en-us/windows/win32/api/adhoc/nf-adhoc-idot11adhocmanagernotificationsink-oninterfaceremove
+ // HRESULT OnInterfaceRemove( GUID *Signature );
+ [PreserveSig]
+ HRESULT OnInterfaceRemove(in Guid Signature);
+ }
+
+ ///
+ ///
+ /// The IDot11AdHocNetwork interface represents an available ad hoc network destination within connection range. Before an
+ /// application can connect to a network, the network must have been created using IDot11AdHocManager::CreateNetwork and committed
+ /// using IDot11AdHocManager::CommitCreatedNetwork.
+ ///
+ ///
+ /// Note Ad hoc mode might not be available in future versions of Windows. Starting with Windows 8.1 and Windows Server 2012
+ /// R2, use Wi-Fi Direct instead.
+ ///
+ ///
+ // https://docs.microsoft.com/en-us/windows/win32/api/adhoc/nn-adhoc-idot11adhocnetwork
+ [PInvokeData("adhoc.h", MSDNShortId = "NN:adhoc.IDot11AdHocNetwork")]
+ [ComImport, Guid("8F10CC29-CF0D-42a0-ACBE-E2DE7007384D"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
+ public interface IDot11AdHocNetwork
+ {
+ /// Gets the connection status of the network.
+ /// A DOT11_ADHOC_NETWORK_CONNECTION_STATUS value that specifies the connection state.
+ // https://docs.microsoft.com/en-us/windows/win32/api/adhoc/nf-adhoc-idot11adhocnetwork-getstatus HRESULT GetStatus(
+ // DOT11_ADHOC_NETWORK_CONNECTION_STATUS *eStatus );
+ DOT11_ADHOC_NETWORK_CONNECTION_STATUS GetStatus();
+
+ /// Gets the SSID of the network.
+ ///
+ /// The SSID of the network.
+ /// You must free this string using CoTaskMemFree.
+ ///
+ // https://docs.microsoft.com/en-us/windows/win32/api/adhoc/nf-adhoc-idot11adhocnetwork-getssid HRESULT GetSSID( LPWSTR
+ // *ppszwSSID );
+ [return: MarshalAs(UnmanagedType.LPWStr)]
+ string GetSSID();
+
+ /// Returns a boolean value that specifies whether there is a saved profile associated with the network.
+ ///
+ /// Specifies whether the network has a profile. This value is set to TRUE if the network has a profile and FALSE otherwise.
+ ///
+ // https://docs.microsoft.com/en-us/windows/win32/api/adhoc/nf-adhoc-idot11adhocnetwork-hasprofile HRESULT HasProfile( BOOLEAN
+ // *pf11d );
+ [return: MarshalAs(UnmanagedType.U1)]
+ bool HasProfile();
+
+ /// Gets the profile name associated with the network.
+ ///
+ /// The name of the profile associated with the network. If the network has no profile, this parameter is NULL.
+ /// You must free this string using CoTaskMemFree.
+ ///
+ // https://docs.microsoft.com/en-us/windows/win32/api/adhoc/nf-adhoc-idot11adhocnetwork-getprofilename HRESULT GetProfileName(
+ // LPWSTR *ppszwProfileName );
+ [return: MarshalAs(UnmanagedType.LPWStr)]
+ string GetProfileName();
+
+ /// Deletes any profile associated with the network.
+ // https://docs.microsoft.com/en-us/windows/win32/api/adhoc/nf-adhoc-idot11adhocnetwork-deleteprofile HRESULT DeleteProfile();
+ void DeleteProfile();
+
+ /// Gets the signal quality values associated with the network's radio.
+ /// The current signal strength. This parameter takes a ULONG value between 0 and puStrengthMax.
+ ///
+ /// The maximum signal strength value. This parameter takes a ULONG value between 0 and 100. By default, puStrengthMax is set to 100.
+ ///
+ ///
+ /// Signal strength, in this context, is measured on a linear scale. When puStrengthMax is set to the default value of 100,
+ /// puStrengthValue represents the percentage of the maximum signal strength currently used for transmission.
+ ///
+ // https://docs.microsoft.com/en-us/windows/win32/api/adhoc/nf-adhoc-idot11adhocnetwork-getsignalquality HRESULT
+ // GetSignalQuality( ULONG *puStrengthValue, ULONG *puStrengthMax );
+ void GetSignalQuality(out uint puStrengthValue, out uint puStrengthMax);
+
+ /// Gets the security settings for the network.
+ /// A pointer to an IDot11AdHocSecuritySettings interface that contains the security settings for the network.
+ // https://docs.microsoft.com/en-us/windows/win32/api/adhoc/nf-adhoc-idot11adhocnetwork-getsecuritysetting HRESULT
+ // GetSecuritySetting( IDot11AdHocSecuritySettings **pAdHocSecuritySetting );
+ IDot11AdHocSecuritySettings GetSecuritySetting();
+
+ ///
+ /// Gets the context identifier associated with the network. This GUID identifies the application that created the network.
+ ///
+ ///
+ /// The context identifier associated with the network. If no ContextGuid was specified when the CreateNetwork call was made,
+ /// the GUID returned consists of all zeros.
+ ///
+ // https://docs.microsoft.com/en-us/windows/win32/api/adhoc/nf-adhoc-idot11adhocnetwork-getcontextguid HRESULT GetContextGuid(
+ // GUID *pContextGuid );
+ Guid GetContextGuid();
+
+ ///
+ /// Gets the unique signature associated with the ad hoc network. The signature uniquely identifies an IDot11AdHocNetwork object
+ /// with a particular set of attributes.
+ ///
+ /// A signature that uniquely identifies an ad hoc network. This signature is generated from certain network attributes.
+ ///
+ /// Do not cache the returned signature locally. Whenever a network object changes, its signature changes. Actions that are not
+ /// associated with notifications, such as saving the network's profile, can cause the signature to change.
+ ///
+ // https://docs.microsoft.com/en-us/windows/win32/api/adhoc/nf-adhoc-idot11adhocnetwork-getsignature HRESULT GetSignature( GUID
+ // *pSignature );
+ Guid GetSignature();
+
+ /// Gets the interface associated with a network.
+ /// A pointer to an IDot11AdHocInterface.
+ // https://docs.microsoft.com/en-us/windows/win32/api/adhoc/nf-adhoc-idot11adhocnetwork-getinterface HRESULT GetInterface(
+ // IDot11AdHocInterface **pAdHocInterface );
+ IDot11AdHocInterface GetInterface();
+
+ ///
+ /// Connects to a previously created wireless ad hoc network. Before an application can connect to a network, the network must
+ /// have been created using IDot11AdHocManager::CreateNetwork and committed using IDot11AdHocManager::CommitCreatedNetwork.
+ ///
+ ///
+ /// The password string used to authenticate the user or machine on the network.
+ ///
+ /// The length of the password string depends on the security settings passed in the pSecurity parameter of the CreateNetwork
+ /// call. The following table shows the password length associated with various security settings.
+ ///
+ ///
+ ///
+ /// Security Settings
+ /// Password Length
+ ///
+ /// -
+ /// Open-None
+ /// 0
+ ///
+ /// -
+ /// Open-WEP
+ /// 5 or 13 characters; 10 or 26 hexadecimal digits
+ ///
+ /// -
+ /// WPA2PSK
+ /// 8 to 63 characters
+ ///
+ ///
+ ///
+ /// For the enumerated values that correspond to the security settings pair above, see DOT11_ADHOC_AUTH_ALGORITHM and DOT11_ADHOC_CIPHER_ALGORITHM.
+ ///
+ ///
+ ///
+ /// The geographical location in which the network was created. For a list of possible values, see Table of Geographical Locations.
+ ///
+ ///
+ ///
+ /// An optional parameter that specifies whether a wireless profile should be saved. If TRUE, the profile is saved to the
+ /// profile store. Once a profile is saved, the user can modify the profile using the Manage Wireless Network user
+ /// interface. Profiles can also be modified using the Native Wifi Functions.
+ ///
+ /// Saving a profile modifies the network signature returned by IDot11AdHocNetwork::GetSignature.
+ ///
+ ///
+ ///
+ /// An optional parameter that specifies whether the profile to be saved is an all-user profile. If set to TRUE, the
+ /// profile is specific to the current user. If set to FALSE, the profile is an all-user profile and can be used by any
+ /// user logged into the machine. This parameter is ignored if fSaveProfile is FALSE.
+ ///
+ ///
+ /// By default, only members of the Administrators group can save an all-user profile. These security settings can be altered
+ /// using the WlanSetSecuritySettings function. Your application must be launched by a user with sufficient privileges for an
+ /// all-user profile to be saved successfully.
+ ///
+ ///
+ /// If your application is running in a Remote Desktop window, you can only save an all-user profile. User-specific profiles
+ /// cannot be saved from an application running remotely.
+ ///
+ ///
+ ///
+ /// This method is asynchronous. Connect returns S_OK immediately if the parameters passed to the method are valid.
+ /// However, a return code of S_OK does not indicate that the connection was successful. You must register for notifications on
+ /// the IDot11AdHocNetworkNotificationSink interface to be notified of connection success or failure. The
+ /// IDot11AdHocNetworkNotificationSink::OnStatusChange method returns the connection status. For more information about
+ /// registering for notifications, see IDot11AdHocManager.
+ ///
+ // https://docs.microsoft.com/en-us/windows/win32/api/adhoc/nf-adhoc-idot11adhocnetwork-connect HRESULT Connect( LPCWSTR
+ // Passphrase, LONG GeographicalId, BOOLEAN fSaveProfile, BOOLEAN fMakeSavedProfileUserSpecific );
+ void Connect([MarshalAs(UnmanagedType.LPWStr)] string Passphrase, int GeographicalId, [MarshalAs(UnmanagedType.U1)] bool fSaveProfile, [MarshalAs(UnmanagedType.U1)] bool fMakeSavedProfileUserSpecific);
+
+ /// Disconnects from an ad hoc network.
+ // https://docs.microsoft.com/en-us/windows/win32/api/adhoc/nf-adhoc-idot11adhocnetwork-disconnect HRESULT Disconnect();
+ void Disconnect();
+ }
+
+ ///
+ ///
+ /// The IDot11AdHocNetworkNotificationSink interface defines the notifications supported by the IDot11AdHocNetwork interface.
+ /// To register for notifications, call the Advise method on an instantiated IDot11AdHocManager object with the
+ /// IDot11AdHocNetworkNotificationSink interface passed as the pUnk parameter. To terminate notifications, call the Unadvise method.
+ ///
+ ///
+ /// Note Ad hoc mode might not be available in future versions of Windows. Starting with Windows 8.1 and Windows Server 2012
+ /// R2, use Wi-Fi Direct instead.
+ ///
+ ///
+ // https://docs.microsoft.com/en-us/windows/win32/api/adhoc/nn-adhoc-idot11adhocnetworknotificationsink
+ [PInvokeData("adhoc.h", MSDNShortId = "NN:adhoc.IDot11AdHocNetworkNotificationSink")]
+ [ComImport, Guid("8F10CC2A-CF0D-42a0-ACBE-E2DE7007384D"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
+ public interface IDot11AdHocNetworkNotificationSink
+ {
+ /// Notifies the client that the connection status of the network has changed.
+ /// A DOT11_ADHOC_NETWORK_CONNECTION_STATUS value that specifies the updated connection status.
+ ///
+ /// Possible return values include, but are not limited to, the following.
+ ///
+ ///
+ /// Return code
+ /// Description
+ ///
+ /// -
+ /// S_OK
+ /// The method completed successfully.
+ ///
+ /// -
+ /// E_FAIL
+ /// The method failed.
+ ///
+ ///
+ ///
+ ///
+ /// This notification is triggered when the connection status changes as a result of connection and disconnection requests
+ /// issued by the current application. It is also triggered when other applications issue successful connection and
+ /// disconnection requests using the IDot11AdHocNetwork methods or the Native Wifi functions. Connection and disconnection
+ /// requests triggered by the user interface will also trigger the OnStatusChange notification.
+ ///
+ // https://docs.microsoft.com/en-us/windows/win32/api/adhoc/nf-adhoc-idot11adhocnetworknotificationsink-onstatuschange HRESULT
+ // OnStatusChange( DOT11_ADHOC_NETWORK_CONNECTION_STATUS eStatus );
+ [PreserveSig]
+ HRESULT OnStatusChange(DOT11_ADHOC_NETWORK_CONNECTION_STATUS eStatus);
+
+ ///
+ /// Notifies the client that a connection attempt failed. The connection attempt may have been initiated by the client itself or
+ /// by another application using the IDot11AdHocNetwork methods or the Native Wifi functions.
+ ///
+ /// A DOT11_ADHOC_CONNECT_FAIL_REASON value that specifies the reason the connection attempt failed.
+ ///
+ /// Possible return values include, but are not limited to, the following.
+ ///
+ ///
+ /// Return code
+ /// Description
+ ///
+ /// -
+ /// S_OK
+ /// The method completed successfully.
+ ///
+ /// -
+ /// E_FAIL
+ /// The method failed.
+ ///
+ ///
+ ///
+ // https://docs.microsoft.com/en-us/windows/win32/api/adhoc/nf-adhoc-idot11adhocnetworknotificationsink-onconnectfail HRESULT
+ // OnConnectFail( DOT11_ADHOC_CONNECT_FAIL_REASON eFailReason );
+ [PreserveSig]
+ HRESULT OnConnectFail(DOT11_ADHOC_CONNECT_FAIL_REASON eFailReason);
+ }
+
+ ///
+ /// The IDot11AdHocSecuritySettings interface specifies the security settings for a wireless ad hoc network.
+ ///
+ /// Note Ad hoc mode might not be available in future versions of Windows. Starting with Windows 8.1 and Windows Server 2012
+ /// R2, use Wi-Fi Direct instead.
+ ///
+ ///
+ // https://docs.microsoft.com/en-us/windows/win32/api/adhoc/nn-adhoc-idot11adhocsecuritysettings
+ [PInvokeData("adhoc.h", MSDNShortId = "NN:adhoc.IDot11AdHocSecuritySettings")]
+ [ComImport, Guid("8F10CC2E-CF0D-42a0-ACBE-E2DE7007384D"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
+ public interface IDot11AdHocSecuritySettings
+ {
+ ///
+ /// Gets the authentication algorithm associated with the security settings. The authentication algorithm is used to
+ /// authenticate machines and users connecting to the ad hoc network associated with an interface.
+ ///
+ /// A pointer to a DOT11_ADHOC_AUTH_ALGORITHM value that specifies the authentication algorithm.
+ // https://docs.microsoft.com/en-us/windows/win32/api/adhoc/nf-adhoc-idot11adhocsecuritysettings-getdot11authalgorithm HRESULT
+ // GetDot11AuthAlgorithm( DOT11_ADHOC_AUTH_ALGORITHM *pAuth );
+ DOT11_ADHOC_AUTH_ALGORITHM GetDot11AuthAlgorithm();
+
+ ///
+ /// Gets the cipher algorithm associated with the security settings. The cipher algorithm is used to encrypt and decrypt
+ /// information sent on the ad hoc network associated with an interface.
+ ///
+ /// A pointer to a DOT11_ADHOC_CIPHER_ALGORITHM value that specifies the cipher algorithm.
+ // https://docs.microsoft.com/en-us/windows/win32/api/adhoc/nf-adhoc-idot11adhocsecuritysettings-getdot11cipheralgorithm HRESULT
+ // GetDot11CipherAlgorithm( DOT11_ADHOC_CIPHER_ALGORITHM *pCipher );
+ DOT11_ADHOC_CIPHER_ALGORITHM GetDot11CipherAlgorithm();
+ }
+
+ ///
+ /// This interface represents the collection of currently visible 802.11 ad hoc network interfaces. It is a standard enumerator.
+ ///
+ /// Note Ad hoc mode might not be available in future versions of Windows. Starting with Windows 8.1 and Windows Server 2012
+ /// R2, use Wi-Fi Direct instead.
+ ///
+ ///
+ // https://docs.microsoft.com/en-us/windows/win32/api/adhoc/nn-adhoc-ienumdot11adhocinterfaces
+ [PInvokeData("adhoc.h", MSDNShortId = "NN:adhoc.IEnumDot11AdHocInterfaces")]
+ [ComImport, Guid("8F10CC2C-CF0D-42a0-ACBE-E2DE7007384D"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
+ public interface IEnumDot11AdHocInterfaces : ICOMEnum
+ {
+ ///
+ /// Gets the specified number of elements from the sequence and advances the current position by the number of items retrieved.
+ /// If there are fewer than the requested number of elements left in the sequence, it retrieves the remaining elements.
+ ///
+ /// The number of elements requested.
+ ///
+ /// A pointer to a variable that, on successful return, points to an array of pointers to IDot11AdHocInterface interfaces. The
+ /// array is of size cElt.
+ ///
+ /// A pointer to a variable that specifies the number of elements returned in rgElt.
+ ///
+ /// Possible return values include, but are not limited to, the following.
+ ///
+ ///
+ /// Return code
+ /// Description
+ ///
+ /// -
+ /// S_OK
+ /// The method completed successfully.
+ ///
+ /// -
+ /// E_FAIL
+ /// The method failed.
+ ///
+ /// -
+ /// E_INVALIDARG
+ /// One of the parameters is invalid.
+ ///
+ /// -
+ /// E_NOINTERFACE
+ /// A specified interface is not supported.
+ ///
+ /// -
+ /// E_OUTOFMEMORY
+ /// The method could not allocate the memory required to perform this operation.
+ ///
+ /// -
+ /// E_POINTER
+ /// A pointer passed as a parameter is not valid.
+ ///
+ ///
+ ///
+ // https://docs.microsoft.com/en-us/windows/win32/api/adhoc/nf-adhoc-ienumdot11adhocinterfaces-next HRESULT Next( ULONG cElt,
+ // IDot11AdHocInterface **rgElt, ULONG *pcEltFetched );
+ [PreserveSig]
+ HRESULT Next(uint cElt, IDot11AdHocInterface[] rgElt, out uint pcEltFetched);
+
+ /// Skips over the next specified number of elements in the enumeration sequence.
+ /// The number of elements to skip.
+ ///
+ /// Possible return values include, but are not limited to, the following.
+ ///
+ ///
+ /// Return code
+ /// Description
+ ///
+ /// -
+ /// S_OK
+ /// The method completed successfully.
+ ///
+ /// -
+ /// E_FAIL
+ /// The method failed.
+ ///
+ ///
+ ///
+ // https://docs.microsoft.com/en-us/windows/win32/api/adhoc/nf-adhoc-ienumdot11adhocinterfaces-skip HRESULT Skip( ULONG cElt );
+ [PreserveSig]
+ HRESULT Skip(uint cElt);
+
+ /// Resets to the beginning of the enumeration sequence.
+ // https://docs.microsoft.com/en-us/windows/win32/api/adhoc/nf-adhoc-ienumdot11adhocinterfaces-reset HRESULT Reset();
+ void Reset();
+
+ /// Creates a new enumeration interface.
+ /// A pointer that, on successful return, points to an IEnumDot11AdHocInterfaces interface.
+ // https://docs.microsoft.com/en-us/windows/win32/api/adhoc/nf-adhoc-ienumdot11adhocinterfaces-clone HRESULT Clone(
+ // IEnumDot11AdHocInterfaces **ppEnum );
+ IEnumDot11AdHocInterfaces Clone();
+ }
+
+ ///
+ /// This interface represents the collection of currently visible 802.11 ad hoc networks. It is a standard enumerator.
+ ///
+ /// Note Ad hoc mode might not be available in future versions of Windows. Starting with Windows 8.1 and Windows Server 2012
+ /// R2, use Wi-Fi Direct instead.
+ ///
+ ///
+ // https://docs.microsoft.com/en-us/windows/win32/api/adhoc/nn-adhoc-ienumdot11adhocnetworks
+ [PInvokeData("adhoc.h", MSDNShortId = "NN:adhoc.IEnumDot11AdHocNetworks")]
+ [ComImport, Guid("8F10CC28-CF0D-42a0-ACBE-E2DE7007384D"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
+ public interface IEnumDot11AdHocNetworks : ICOMEnum
+ {
+ ///
+ /// Gets the specified number of elements from the sequence and advances the current position by the number of items retrieved.
+ /// If there are fewer than the requested number of elements left in the sequence, it retrieves the remaining elements.
+ ///
+ /// The number of elements requested.
+ ///
+ /// A pointer to the first element in an array of IDot11AdHocNetwork interfaces. The array is of size cElt. The array must exist
+ /// and be of size cElt (at a minimum) before the Next method is called, although the array need not be initialized. Upon
+ /// return, the previously existing array will contain pointers to IDot11AdHocNetwork objects.
+ ///
+ /// A pointer to a variable that specifies the number of elements returned in rgElt.
+ ///
+ /// Possible return values include, but are not limited to, the following.
+ ///
+ ///
+ /// Return code
+ /// Description
+ ///
+ /// -
+ /// S_OK
+ /// The method completed successfully.
+ ///
+ /// -
+ /// E_FAIL
+ /// The method failed.
+ ///
+ /// -
+ /// E_INVALIDARG
+ /// One of the parameters is invalid.
+ ///
+ /// -
+ /// E_NOINTERFACE
+ /// A specified interface is not supported.
+ ///
+ /// -
+ /// E_OUTOFMEMORY
+ /// The method could not allocate the memory required to perform this operation.
+ ///
+ /// -
+ /// E_POINTER
+ /// A pointer passed as a parameter is not valid.
+ ///
+ ///
+ ///
+ // https://docs.microsoft.com/en-us/windows/win32/api/adhoc/nf-adhoc-ienumdot11adhocnetworks-next HRESULT Next( ULONG cElt,
+ // IDot11AdHocNetwork **rgElt, ULONG *pcEltFetched );
+ [PreserveSig]
+ HRESULT Next(uint cElt, IDot11AdHocNetwork[] rgElt, out uint pcEltFetched);
+
+ /// Skips over the next specified number of elements in the enumeration sequence.
+ /// The number of elements to skip.
+ ///
+ /// Possible return values include, but are not limited to, the following.
+ ///
+ ///
+ /// Return code
+ /// Description
+ ///
+ /// -
+ /// S_OK
+ /// The method completed successfully.
+ ///
+ /// -
+ /// E_FAIL
+ /// The method failed.
+ ///
+ ///
+ ///
+ // https://docs.microsoft.com/en-us/windows/win32/api/adhoc/nf-adhoc-ienumdot11adhocnetworks-skip HRESULT Skip( ULONG cElt );
+ [PreserveSig]
+ HRESULT Skip(uint cElt);
+
+ /// Resets to the beginning of the enumeration sequence.
+ // https://docs.microsoft.com/en-us/windows/win32/api/adhoc/nf-adhoc-ienumdot11adhocnetworks-reset HRESULT Reset();
+ void Reset();
+
+ /// Creates a new enumeration interface.
+ /// A pointer to a variable that, on successful return, points to an IEnumDot11AdHocNetworks interface.
+ // https://docs.microsoft.com/en-us/windows/win32/api/adhoc/nf-adhoc-ienumdot11adhocnetworks-clone HRESULT Clone(
+ // IEnumDot11AdHocNetworks **ppEnum );
+ IEnumDot11AdHocNetworks Clone();
+ }
+
+ ///
+ ///
+ /// This interface represents the collection of security settings associated with each visible wireless ad hoc network. It is a
+ /// standard enumerator.
+ ///
+ ///
+ /// Note Ad hoc mode might not be available in future versions of Windows. Starting with Windows 8.1 and Windows Server 2012
+ /// R2, use Wi-Fi Direct instead.
+ ///
+ ///
+ // https://docs.microsoft.com/en-us/windows/win32/api/adhoc/nn-adhoc-ienumdot11adhocsecuritysettings
+ [PInvokeData("adhoc.h", MSDNShortId = "NN:adhoc.IEnumDot11AdHocSecuritySettings")]
+ [ComImport, Guid("8F10CC2D-CF0D-42a0-ACBE-E2DE7007384D"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
+ public interface IEnumDot11AdHocSecuritySettings : ICOMEnum
+ {
+ ///
+ /// Gets the specified number of elements from the sequence and advances the current position by the number of items retrieved.
+ /// If there are fewer than the requested number of elements left in the sequence, it retrieves the remaining elements.
+ ///
+ /// The number of elements requested.
+ ///
+ /// A pointer to a variable that, on successful return, points an array of pointers to IDot11AdHocSecuritySettings interfaces.
+ /// The array is of size cElt.
+ ///
+ /// A pointer to a variable that specifies the number of elements returned in rgElt.
+ ///
+ /// Possible return values include, but are not limited to, the following.
+ ///
+ ///
+ /// Return code
+ /// Description
+ ///
+ /// -
+ /// S_OK
+ /// The method completed successfully.
+ ///
+ /// -
+ /// E_FAIL
+ /// The method failed.
+ ///
+ /// -
+ /// E_INVALIDARG
+ /// One of the parameters is invalid.
+ ///
+ /// -
+ /// E_NOINTERFACE
+ /// A specified interface is not supported.
+ ///
+ /// -
+ /// E_OUTOFMEMORY
+ /// The method could not allocate the memory required to perform this operation.
+ ///
+ /// -
+ /// E_POINTER
+ /// A pointer passed as a parameter is not valid.
+ ///
+ ///
+ ///
+ // https://docs.microsoft.com/en-us/windows/win32/api/adhoc/nf-adhoc-ienumdot11adhocsecuritysettings-next HRESULT Next( ULONG
+ // cElt, IDot11AdHocSecuritySettings **rgElt, ULONG *pcEltFetched );
+ [PreserveSig]
+ HRESULT Next(uint cElt, IDot11AdHocSecuritySettings[] rgElt, out uint pcEltFetched);
+
+ /// Skips over the next specified number of elements in the enumeration sequence.
+ /// The number of elements to skip.
+ ///
+ /// Possible return values include, but are not limited to, the following.
+ ///
+ ///
+ /// Return code
+ /// Description
+ ///
+ /// -
+ /// S_OK
+ /// The method completed successfully.
+ ///
+ /// -
+ /// E_FAIL
+ /// The method failed.
+ ///
+ ///
+ ///
+ // https://docs.microsoft.com/en-us/windows/win32/api/adhoc/nf-adhoc-ienumdot11adhocsecuritysettings-skip HRESULT Skip( ULONG
+ // cElt );
+ [PreserveSig]
+ HRESULT Skip(uint cElt);
+
+ /// Resets to the beginning of the enumeration sequence.
+ // https://docs.microsoft.com/en-us/windows/win32/api/adhoc/nf-adhoc-ienumdot11adhocsecuritysettings-reset HRESULT Reset();
+ void Reset();
+
+ /// Creates a new enumeration interface.
+ /// A pointer that, on successful return, points to an IEnumDot11AdHocSecuritySettings interface.
+ // https://docs.microsoft.com/en-us/windows/win32/api/adhoc/nf-adhoc-ienumdot11adhocsecuritysettings-clone HRESULT Clone(
+ // IEnumDot11AdHocSecuritySettings **ppEnum );
+ IEnumDot11AdHocSecuritySettings Clone();
+ }
+
+ /// CLSID_AdHocManager
+ [PInvokeData("adhoc.h", MSDNShortId = "NN:adhoc.IDot11AdHocManager")]
+ [ComImport, Guid("DD06A84F-83BD-4d01-8AB9-2389FEA0869E"), ClassInterface(ClassInterfaceType.None)]
+ public class Dot11AdHocManager { }
+ }
+}
\ No newline at end of file
diff --git a/UnitTests/PInvoke/WlanApi/AdhocTests.cs b/UnitTests/PInvoke/WlanApi/AdhocTests.cs
new file mode 100644
index 00000000..3c469d20
--- /dev/null
+++ b/UnitTests/PInvoke/WlanApi/AdhocTests.cs
@@ -0,0 +1,99 @@
+using NUnit.Framework;
+using System;
+using Vanara.InteropServices;
+using Vanara.PInvoke;
+using Vanara.PInvoke.Tests;
+using static Vanara.PInvoke.WlanApi;
+
+namespace WlanApi
+{
+ [TestFixture]
+ public class AdhocTests
+ {
+ public const string ADHOC_PWD = "adhocpwd4testing";
+ public const string ADHOC_SSID = "ADHOCWIFI";
+ public const int geoId = 244; // USA
+
+ [Test]
+ public void AdhocMgrTest()
+ {
+ IDot11AdHocManager AdHocManager = new();
+ cManagerSink mSink = new();
+ using var pConnectionPointContainer = new ComConnectionPoint(AdHocManager, mSink);
+
+ var networks = AdHocManager.GetIEnumDot11AdHocNetworks();
+
+ IDot11AdHocNetwork myNet = null;
+ foreach (var network in new Vanara.Collections.IEnumFromCom(networks.Next, networks.Reset))
+ {
+ var ssid = network.GetSSID();
+ TestContext.WriteLine("\tssid = {0}", ssid);
+ if (ssid == ADHOC_SSID)
+ myNet = network;
+ }
+
+ var sink = new cSink();
+ if (myNet is not null)
+ {
+ using var netcp = new ComConnectionPoint(myNet, sink);
+ myNet.Connect(ADHOC_PWD, geoId, false, false);
+ }
+ else
+ {
+ var securitySettings = new cSecuritySettings();
+ myNet = AdHocManager.CreateNetwork(ADHOC_SSID, ADHOC_PWD, geoId, default, securitySettings);
+ using var netcp = new ComConnectionPoint(myNet, sink);
+ AdHocManager.CommitCreatedNetwork(myNet, false, false);
+ }
+ }
+
+ private class cManagerSink : IDot11AdHocManagerNotificationSink
+ {
+ HRESULT IDot11AdHocManagerNotificationSink.OnInterfaceAdd(IDot11AdHocInterface pIAdHocInterface)
+ {
+ TestContext.Write("[ManagerNotif] New interface\n");
+ return HRESULT.S_OK;
+ }
+
+ HRESULT IDot11AdHocManagerNotificationSink.OnInterfaceRemove(in Guid Signature)
+ {
+ TestContext.Write("[ManagerNotif] interface removed\n");
+ return HRESULT.S_OK;
+ }
+
+ HRESULT IDot11AdHocManagerNotificationSink.OnNetworkAdd(IDot11AdHocNetwork pIAdHocNetwork)
+ {
+ TestContext.Write("[ManagerNotif] New network : {0}\n", pIAdHocNetwork.GetSSID());
+ return HRESULT.S_OK;
+ }
+
+ HRESULT IDot11AdHocManagerNotificationSink.OnNetworkRemove(in Guid Signature)
+ {
+ TestContext.Write("[ManagerNotif] network removed\n");
+ return HRESULT.S_OK;
+ }
+ }
+
+ private class cSecuritySettings : IDot11AdHocSecuritySettings
+ {
+ DOT11_ADHOC_AUTH_ALGORITHM IDot11AdHocSecuritySettings.GetDot11AuthAlgorithm() => DOT11_ADHOC_AUTH_ALGORITHM.DOT11_ADHOC_AUTH_ALGO_80211_OPEN;
+
+ DOT11_ADHOC_CIPHER_ALGORITHM IDot11AdHocSecuritySettings.GetDot11CipherAlgorithm() => DOT11_ADHOC_CIPHER_ALGORITHM.DOT11_ADHOC_CIPHER_ALGO_WEP;
+ }
+
+ private class cSink : IDot11AdHocNetworkNotificationSink
+ {
+ HRESULT IDot11AdHocNetworkNotificationSink.OnConnectFail(DOT11_ADHOC_CONNECT_FAIL_REASON reason)
+ {
+ TestContext.WriteLine($"[NetworkNotif] Connection failed : {reason}");
+ return HRESULT.S_OK;
+ }
+
+ HRESULT IDot11AdHocNetworkNotificationSink.OnStatusChange(DOT11_ADHOC_NETWORK_CONNECTION_STATUS status)
+ {
+ TestContext.WriteLine($"[NetworkNotif] Status changed : {status}");
+ return HRESULT.S_OK;
+ }
+ }
+ }
+}
\ No newline at end of file