microsoft / CsWin32

A source generator to add a user-defined set of Win32 P/Invoke methods and supporting types to a C# project.
MIT License
1.99k stars 84 forks source link

WlanOpenHandle doesn't support SafeHandle #1200

Closed Samael7777 closed 3 weeks ago

Samael7777 commented 3 weeks ago

Actual behavior

WlanOpenHandle is generating only with unsafe handle, but other wlan api procs needs SafeHandle.

Expected behavior

WlanOpenHandle must return SafeHandle, when it is set in settings.

Repro steps

  1. NativeMethods.txt content:

    WlanOpenHandle
    WlanCloseHandle
    WlanGetProfileList
    WlanEnumInterfaces
    WlanGetProfile
  2. NativeMethods.json content (if present):

    {
    "$schema": "https://aka.ms/CsWin32.schema.json",
    "useSafeHandles": true,
    "public": true,
    "className": "Winapi"
    }
  3. Any of your own code that should be shared? Windows.Win32.Winapi.wlanapi.dll.g.cs

    
    // <auto-generated>
    //     This code was generated by a tool.
    //
    //     Changes to this file may cause incorrect behavior and will be lost if
    //     the code is regenerated.
    // </auto-generated>
    // ------------------------------------------------------------------------------

pragma warning disable CS1591,CS1573,CS0465,CS0649,CS8019,CS1570,CS1584,CS1658,CS0436,CS8981

using global::System; using global::System.Diagnostics; using global::System.Diagnostics.CodeAnalysis; using global::System.Runtime.CompilerServices; using global::System.Runtime.InteropServices; using global::System.Runtime.Versioning; using winmdroot = global::Windows.Win32; namespace Windows.Win32 {

/// <content>
/// Contains extern methods from "wlanapi.dll".
/// </content>
public static partial class Winapi
{
    /// <inheritdoc cref="WlanOpenHandle(uint, void*, uint*, winmdroot.Foundation.HANDLE*)"/>
    [SupportedOSPlatform("windows6.0.6000")]
    public static unsafe uint WlanOpenHandle(uint dwClientVersion, out uint pdwNegotiatedVersion, winmdroot.Foundation.HANDLE* phClientHandle)
    {
        fixed (uint* pdwNegotiatedVersionLocal = &pdwNegotiatedVersion)
        {
            uint __result = Winapi.WlanOpenHandle(dwClientVersion, default, pdwNegotiatedVersionLocal, phClientHandle);
            return __result;
        }
    }

    /// <summary>Opens a connection to the server.</summary>
    /// <param name="dwClientVersion">
    /// <para>The highest version of the WLAN API that the client supports. </para>
    /// <para>This doc was truncated.</para>
    /// <para><see href="https://learn.microsoft.com/windows/win32/api/wlanapi/nf-wlanapi-wlanopenhandle#parameters">Read more on docs.microsoft.com</see>.</para>
    /// </param>
    /// <param name="pReserved">Reserved for future use.  Must be set to <b>NULL</b>.</param>
    /// <param name="pdwNegotiatedVersion">The version of the WLAN API that will be used in this session.  This value is usually the highest version supported by both the client and server.</param>
    /// <param name="phClientHandle">A handle for the client to use in this session.  This handle is used by other functions throughout the session.</param>
    /// <returns>
    /// <para>If the function succeeds, the return value is ERROR_SUCCESS. If the function fails, the return value may be one of the following return codes. </para>
    /// <para>This doc was truncated.</para>
    /// </returns>
    /// <remarks>
    /// <para>The version number specified by <i>dwClientVersion</i> and <i>pdwNegotiatedVersion</i> is a composite version number made up of both major and minor versions. The major version is specified by the low-order word, and the minor version is specified by the high-order word. The macros <c>WLAN_API_VERSION_MAJOR(_v)</code> and <code>WLAN_API_VERSION_MINOR(_v)</code> return the major and minor version numbers respectively. You can construct a version number using the macro <code>WLAN_API_MAKE_VERSION(_major, _minor)</c>. <b>Windows XP with SP3 and Wireless LAN API for Windows XP with SP2:  </b><b>WlanOpenHandle</b> will return an error message if the Wireless Zero Configuration (WZC) service has not been started or if the WZC service is not responsive.</para>
    /// <para><see href="https://learn.microsoft.com/windows/win32/api/wlanapi/nf-wlanapi-wlanopenhandle#">Read more on docs.microsoft.com</see>.</para>
    /// </remarks>
    [DllImport("wlanapi.dll", ExactSpelling = true)]
    [DefaultDllImportSearchPaths(DllImportSearchPath.System32)]
    [SupportedOSPlatform("windows6.0.6000")]
    public static extern unsafe uint WlanOpenHandle(uint dwClientVersion, [Optional] void* pReserved, uint* pdwNegotiatedVersion, winmdroot.Foundation.HANDLE* phClientHandle);

    /// <inheritdoc cref="WlanCloseHandle(winmdroot.Foundation.HANDLE, void*)"/>
    [SupportedOSPlatform("windows6.0.6000")]
    public static unsafe uint WlanCloseHandle(SafeHandle hClientHandle)
    {
        bool hClientHandleAddRef = false;
        try
        {
            winmdroot.Foundation.HANDLE hClientHandleLocal;
            if (hClientHandle is object)
            {
                hClientHandle.DangerousAddRef(ref hClientHandleAddRef);
                hClientHandleLocal = (winmdroot.Foundation.HANDLE)hClientHandle.DangerousGetHandle();
            }
            else
                throw new ArgumentNullException(nameof(hClientHandle));
            uint __result = Winapi.WlanCloseHandle(hClientHandleLocal, default);
            return __result;
        }
        finally
        {
            if (hClientHandleAddRef)
                hClientHandle.DangerousRelease();
        }
    }

    /// <summary>Closes a connection to the server.</summary>
    /// <param name="hClientHandle">The client's session handle, which identifies the connection to be closed. This handle was  obtained by a previous call to the <a href="https://docs.microsoft.com/windows/desktop/api/wlanapi/nf-wlanapi-wlanopenhandle">WlanOpenHandle</a> function.</param>
    /// <param name="pReserved">Reserved for future use.  Set this parameter to <b>NULL</b>.</param>
    /// <returns>
    /// <para>If the function succeeds, the return value is ERROR_SUCCESS. If the function fails, the return value may be one of the following return codes. </para>
    /// <para>This doc was truncated.</para>
    /// </returns>
    /// <remarks>
    /// <para>After a connection has been closed, any attempted use of the closed handle can cause unexpected errors.  Upon closing, all outstanding notifications are discarded. Do not call <b>WlanCloseHandle</b> from a callback function. If the client is in the middle of a notification callback when <b>WlanCloseHandle</b> is called, the function waits for the callback to finish before returning a value.  Calling this function inside a callback function will result in the call never completing. If both the callback function and the thread that closes the handle try to acquire the same lock, a deadlock may occur. In addition, do not call <b>WlanCloseHandle</b> from the <b>DllMain</b> function in an application DLL. This could also cause a deadlock.</para>
    /// <para><see href="https://learn.microsoft.com/windows/win32/api/wlanapi/nf-wlanapi-wlanclosehandle#">Read more on docs.microsoft.com</see>.</para>
    /// </remarks>
    [DllImport("wlanapi.dll", ExactSpelling = true)]
    [DefaultDllImportSearchPaths(DllImportSearchPath.System32)]
    [SupportedOSPlatform("windows6.0.6000")]
    public static extern unsafe uint WlanCloseHandle(winmdroot.Foundation.HANDLE hClientHandle, [Optional] void* pReserved);

    /// <inheritdoc cref="WlanGetProfileList(winmdroot.Foundation.HANDLE, global::System.Guid*, void*, winmdroot.NetworkManagement.WiFi.WLAN_PROFILE_INFO_LIST**)"/>
    [SupportedOSPlatform("windows6.0.6000")]
    public static unsafe uint WlanGetProfileList(SafeHandle hClientHandle, in global::System.Guid pInterfaceGuid, out winmdroot.NetworkManagement.WiFi.WLAN_PROFILE_INFO_LIST* ppProfileList)
    {
        bool hClientHandleAddRef = false;
        try
        {
            fixed (winmdroot.NetworkManagement.WiFi.WLAN_PROFILE_INFO_LIST** ppProfileListLocal = &ppProfileList)
            {
                fixed (global::System.Guid* pInterfaceGuidLocal = &pInterfaceGuid)
                {
                    winmdroot.Foundation.HANDLE hClientHandleLocal;
                    if (hClientHandle is object)
                    {
                        hClientHandle.DangerousAddRef(ref hClientHandleAddRef);
                        hClientHandleLocal = (winmdroot.Foundation.HANDLE)hClientHandle.DangerousGetHandle();
                    }
                    else
                        throw new ArgumentNullException(nameof(hClientHandle));
                    uint __result = Winapi.WlanGetProfileList(hClientHandleLocal, pInterfaceGuidLocal, default, ppProfileListLocal);
                    return __result;
                }
            }
        }
        finally
        {
            if (hClientHandleAddRef)
                hClientHandle.DangerousRelease();
        }
    }

    /// <summary>Retrieves the list of profiles.</summary>
    /// <param name="hClientHandle">The client's session handle, obtained by a previous call to the <a href="https://docs.microsoft.com/windows/desktop/api/wlanapi/nf-wlanapi-wlanopenhandle">WlanOpenHandle</a> function.</param>
    /// <param name="pInterfaceGuid">
    /// <para>The GUID of the wireless interface. A list of the GUIDs for wireless interfaces on the local computer can be retrieved using the <a href="https://docs.microsoft.com/windows/desktop/api/wlanapi/nf-wlanapi-wlanenuminterfaces">WlanEnumInterfaces</a> function.</para>
    /// <para><see href="https://learn.microsoft.com/windows/win32/api/wlanapi/nf-wlanapi-wlangetprofilelist#parameters">Read more on docs.microsoft.com</see>.</para>
    /// </param>
    /// <param name="pReserved">Reserved for future use.  Must be set to <b>NULL</b>.</param>
    /// <param name="ppProfileList">A <a href="https://docs.microsoft.com/windows/desktop/api/wlanapi/ns-wlanapi-wlan_profile_info_list">PWLAN_PROFILE_INFO_LIST</a> structure that contains the list of profile information.</param>
    /// <returns>
    /// <para>If the function succeeds, the return value is ERROR_SUCCESS. If the function fails, the return value may be one of the following return codes. </para>
    /// <para>This doc was truncated.</para>
    /// </returns>
    /// <remarks>
    /// <para>The <b>WlanGetProfileList</b> function returns only the basic information on the wireless profiles on a wireless interface. The list of wireless profiles   on a wireless interface are retrieved in the preference order. The <a href="https://docs.microsoft.com/windows/desktop/api/wlanapi/nf-wlanapi-wlansetprofileposition">WlanSetProfilePosition</a> can be used to change the preference order for the wireless profiles on a wireless interface. More detailed information for a wireless profile on a wireless interface can be retrieved by using the <a href="https://docs.microsoft.com/windows/desktop/api/wlanapi/nf-wlanapi-wlangetprofile">WlanGetProfile</a> function. The <a href="https://docs.microsoft.com/windows/desktop/api/wlanapi/nf-wlanapi-wlangetprofilecustomuserdata">WlanGetProfileCustomUserData</a> function can be used to retrieve custom user data for a wireless profile on a wireless interface. A list of the wireless interfaces and associated GUIDs on the local computer can be retrieved using the <a href="https://docs.microsoft.com/windows/desktop/api/wlanapi/nf-wlanapi-wlanenuminterfaces">WlanEnumInterfaces</a> function. The  <b>WlanGetProfileList</b> function allocates memory for the list of profiles returned in the buffer pointed to by the <i>ppProfileList</i> parameter. The caller is responsible for freeing this memory using the <a href="https://docs.microsoft.com/windows/desktop/api/wlanapi/nf-wlanapi-wlanfreememory">WlanFreeMemory</a> function when this buffer is no longer needed. <b>Windows XP with SP3 and Wireless LAN API for Windows XP with SP2:  </b>Guest profiles, profiles with Wireless Provisioning Service (WPS) authentication, and profiles with Wi-Fi Protected Access-None (WPA-None)  authentication are not supported. These types of profiles are not returned by <b>WlanGetProfileList</b>, even if a profile of this type appears on the preferred profile list.</para>
    /// <para><see href="https://learn.microsoft.com/windows/win32/api/wlanapi/nf-wlanapi-wlangetprofilelist#">Read more on docs.microsoft.com</see>.</para>
    /// </remarks>
    [DllImport("wlanapi.dll", ExactSpelling = true)]
    [DefaultDllImportSearchPaths(DllImportSearchPath.System32)]
    [SupportedOSPlatform("windows6.0.6000")]
    public static extern unsafe uint WlanGetProfileList(winmdroot.Foundation.HANDLE hClientHandle, global::System.Guid* pInterfaceGuid, [Optional] void* pReserved, winmdroot.NetworkManagement.WiFi.WLAN_PROFILE_INFO_LIST** ppProfileList);

    /// <inheritdoc cref="WlanEnumInterfaces(winmdroot.Foundation.HANDLE, void*, winmdroot.NetworkManagement.WiFi.WLAN_INTERFACE_INFO_LIST**)"/>
    [SupportedOSPlatform("windows6.0.6000")]
    public static unsafe uint WlanEnumInterfaces(SafeHandle hClientHandle, out winmdroot.NetworkManagement.WiFi.WLAN_INTERFACE_INFO_LIST* ppInterfaceList)
    {
        bool hClientHandleAddRef = false;
        try
        {
            fixed (winmdroot.NetworkManagement.WiFi.WLAN_INTERFACE_INFO_LIST** ppInterfaceListLocal = &ppInterfaceList)
            {
                winmdroot.Foundation.HANDLE hClientHandleLocal;
                if (hClientHandle is object)
                {
                    hClientHandle.DangerousAddRef(ref hClientHandleAddRef);
                    hClientHandleLocal = (winmdroot.Foundation.HANDLE)hClientHandle.DangerousGetHandle();
                }
                else
                    throw new ArgumentNullException(nameof(hClientHandle));
                uint __result = Winapi.WlanEnumInterfaces(hClientHandleLocal, default, ppInterfaceListLocal);
                return __result;
            }
        }
        finally
        {
            if (hClientHandleAddRef)
                hClientHandle.DangerousRelease();
        }
    }

    /// <summary>Enumerates all of the wireless LAN interfaces currently enabled on the local computer.</summary>
    /// <param name="hClientHandle">The client's session handle, obtained by a previous call to the <a href="https://docs.microsoft.com/windows/desktop/api/wlanapi/nf-wlanapi-wlanopenhandle">WlanOpenHandle</a> function.</param>
    /// <param name="pReserved">Reserved for future use. This parameter must be set to <b>NULL</b>.</param>
    /// <param name="ppInterfaceList">
    /// <para>A pointer to storage for a pointer to receive the returned list of wireless LAN interfaces in a <a href="https://docs.microsoft.com/windows/desktop/api/wlanapi/ns-wlanapi-wlan_interface_info_list">WLAN_INTERFACE_INFO_LIST</a> structure. The buffer for the <a href="https://docs.microsoft.com/windows/desktop/api/wlanapi/ns-wlanapi-wlan_interface_info_list">WLAN_INTERFACE_INFO_LIST</a> returned is allocated by the <b>WlanEnumInterfaces</b> function if the call succeeds.</para>
    /// <para><see href="https://learn.microsoft.com/windows/win32/api/wlanapi/nf-wlanapi-wlanenuminterfaces#parameters">Read more on docs.microsoft.com</see>.</para>
    /// </param>
    /// <returns>
    /// <para>If the function succeeds, the return value is ERROR_SUCCESS. If the function fails, the return value may be one of the following return codes. </para>
    /// <para>This doc was truncated.</para>
    /// </returns>
    /// <remarks>The <b>WlanEnumInterfaces</b> function allocates memory for the list of returned interfaces that is returned in the buffer pointed to by the <i>ppInterfaceList</i> parameter when the function succeeds. The memory used for the buffer pointed to by <i>ppInterfaceList</i> parameter should be released by calling the <a href="https://docs.microsoft.com/windows/desktop/api/wlanapi/nf-wlanapi-wlanfreememory">WlanFreeMemory</a> function after the buffer is no longer needed.</remarks>
    [DllImport("wlanapi.dll", ExactSpelling = true)]
    [DefaultDllImportSearchPaths(DllImportSearchPath.System32)]
    [SupportedOSPlatform("windows6.0.6000")]
    public static extern unsafe uint WlanEnumInterfaces(winmdroot.Foundation.HANDLE hClientHandle, [Optional] void* pReserved, winmdroot.NetworkManagement.WiFi.WLAN_INTERFACE_INFO_LIST** ppInterfaceList);

    /// <inheritdoc cref="WlanGetProfile(winmdroot.Foundation.HANDLE, global::System.Guid*, winmdroot.Foundation.PCWSTR, void*, winmdroot.Foundation.PWSTR*, uint*, uint*)"/>
    [SupportedOSPlatform("windows6.0.6000")]
    public static unsafe uint WlanGetProfile(SafeHandle hClientHandle, in global::System.Guid pInterfaceGuid, string strProfileName, out winmdroot.Foundation.PWSTR pstrProfileXml, uint* pdwFlags, uint* pdwGrantedAccess)
    {
        bool hClientHandleAddRef = false;
        try
        {
            fixed (winmdroot.Foundation.PWSTR* pstrProfileXmlLocal = &pstrProfileXml)
            {
                fixed (char* strProfileNameLocal = strProfileName)
                {
                    fixed (global::System.Guid* pInterfaceGuidLocal = &pInterfaceGuid)
                    {
                        winmdroot.Foundation.HANDLE hClientHandleLocal;
                        if (hClientHandle is object)
                        {
                            hClientHandle.DangerousAddRef(ref hClientHandleAddRef);
                            hClientHandleLocal = (winmdroot.Foundation.HANDLE)hClientHandle.DangerousGetHandle();
                        }
                        else
                            throw new ArgumentNullException(nameof(hClientHandle));
                        uint __result = Winapi.WlanGetProfile(hClientHandleLocal, pInterfaceGuidLocal, strProfileNameLocal, default, pstrProfileXmlLocal, pdwFlags, pdwGrantedAccess);
                        return __result;
                    }
                }
            }
        }
        finally
        {
            if (hClientHandleAddRef)
                hClientHandle.DangerousRelease();
        }
    }

    /// <summary>Retrieves all information about a specified wireless profile.</summary>
    /// <param name="hClientHandle">The client's session handle, obtained by a previous call to the <a href="https://docs.microsoft.com/windows/desktop/api/wlanapi/nf-wlanapi-wlanopenhandle">WlanOpenHandle</a> function.</param>
    /// <param name="pInterfaceGuid">
    /// <para>The GUID of the wireless interface. A list of the GUIDs for wireless interfaces on the local computer can be retrieved using the <a href="https://docs.microsoft.com/windows/desktop/api/wlanapi/nf-wlanapi-wlanenuminterfaces">WlanEnumInterfaces</a> function.</para>
    /// <para><see href="https://learn.microsoft.com/windows/win32/api/wlanapi/nf-wlanapi-wlangetprofile#parameters">Read more on docs.microsoft.com</see>.</para>
    /// </param>
    /// <param name="strProfileName">
    /// <para>The name of the profile. Profile names are case-sensitive. This string must be NULL-terminated. The maximum length of the profile name is 255 characters. This means that the maximum length of this string, including the NULL terminator, is 256 characters. <b>Windows XP with SP3 and Wireless LAN API for Windows XP with SP2:  </b>The name of the profile is derived automatically from the SSID of the network. For infrastructure network profiles, the name of the profile is the SSID of the network. For ad hoc network profiles, the name of the profile is the SSID of the ad hoc network followed by <c>-adhoc</c>.</para>
    /// <para><see href="https://learn.microsoft.com/windows/win32/api/wlanapi/nf-wlanapi-wlangetprofile#parameters">Read more on docs.microsoft.com</see>.</para>
    /// </param>
    /// <param name="pReserved">Reserved for future use.  Must be set to <b>NULL</b>.</param>
    /// <param name="pstrProfileXml">A string that is the XML representation of the queried profile. There is no predefined maximum string length.</param>
    /// <param name="pdwFlags">
    /// <para>On input, a pointer to the address location used to provide additional information about the request. If this parameter is <b>NULL</b> on input, then no information on profile flags will be returned. On output,  a pointer to the address location used to receive profile flags. <b>Windows XP with SP3 and Wireless LAN API for Windows XP with SP2:  </b>Per-user profiles are not supported. Set this parameter to <b>NULL</b>.</para>
    /// <para>The <i>pdwFlags</i> parameter can point to an address location that contains the following values:</para>
    /// <para></para>
    /// <para>This doc was truncated.</para>
    /// <para><see href="https://learn.microsoft.com/windows/win32/api/wlanapi/nf-wlanapi-wlangetprofile#parameters">Read more on docs.microsoft.com</see>.</para>
    /// </param>
    /// <param name="pdwGrantedAccess">
    /// <para>The access mask of the all-user profile. </para>
    /// <para>This doc was truncated.</para>
    /// <para><see href="https://learn.microsoft.com/windows/win32/api/wlanapi/nf-wlanapi-wlangetprofile#parameters">Read more on docs.microsoft.com</see>.</para>
    /// </param>
    /// <returns>
    /// <para>If the function succeeds, the return value is ERROR_SUCCESS. If the function fails, the return value may be one of the following return codes. </para>
    /// <para>This doc was truncated.</para>
    /// </returns>
    /// <remarks>
    /// <para>If the <b>WlanGetProfile</b> function succeeds, the wireless profile is returned in the buffer pointed to by the <i>pstrProfileXml</i> parameter. The buffer contains a string that is the XML representation of the queried profile. For a description of the XML representation of the wireless profile, see <a href="https://docs.microsoft.com/windows/desktop/NativeWiFi/wlan-policyschema-schema">WLAN_profile Schema</a>. The caller is responsible for calling the <a href="https://docs.microsoft.com/windows/desktop/api/wlanapi/nf-wlanapi-wlanfreememory">WlanFreeMemory</a> function to free the memory allocated for the buffer pointer to by the <i>pstrProfileXml</i> parameter when the buffer is no longer needed. If <i>pstrProfileXml</i> specifies an all-user profile, the <b>WlanGetProfile</b>  caller must have read access on the profile. Otherwise, the <b>WlanGetProfile</b> call will fail with a return value of <b>ERROR_ACCESS_DENIED</b>. The permissions on an all-user profile are established when the profile is created or saved using <a href="https://docs.microsoft.com/windows/desktop/api/wlanapi/nf-wlanapi-wlansetprofile">WlanSetProfile</a> or <a href="https://docs.microsoft.com/windows/desktop/api/wlanapi/nf-wlanapi-wlansavetemporaryprofile">WlanSaveTemporaryProfile</a>. <b>Windows 7:  </b><p class="note">The <a href="https://docs.microsoft.com/windows/desktop/NativeWiFi/wlan-profileschema-keymaterial-sharedkey-element">keyMaterial</a> element returned in the profile schema pointed to by the <i>pstrProfileXml</i> may be requested as plaintext if the <b>WlanGetProfile</b> function is called with the <b>WLAN_PROFILE_GET_PLAINTEXT_KEY</b>  flag set in the value pointed to by the <i>pdwFlags</i> parameter on input. <p class="note">For a WEP key, both 5 ASCII characters or 10 hexadecimal characters can be used to set the plaintext key when the profile is created or updated. However, a WEP profile will be saved with  10 hexadecimal characters in the key no matter what the original input was used to create the profile. So in the profile returned by the  <b>WlanGetProfile</b> function, the plaintext WEP key  is always returned as 10 hexadecimal characters.</para>
    /// <para><p class="note">For the <b>WlanGetProfile</b> call to return the plain text key, the <b>wlan_secure_get_plaintext_key</b> permissions from the <a href="https://docs.microsoft.com/windows/desktop/api/wlanapi/ne-wlanapi-wlan_securable_object">WLAN_SECURABLE_OBJECT</a> enumerated type must be set on the calling thread. The DACL must also contain an ACE that grants <b>WLAN_READ_ACCESS</b> permission to the access token of the calling thread. By default,  the permissions for retrieving the plain text key is allowed only to the members of the Administrators group on a local machine.</para>
    /// <para><p class="note">If the calling thread lacks the required permissions, the <b>WlanGetProfile</b> function returns the encrypted key in the <a href="https://docs.microsoft.com/windows/desktop/NativeWiFi/wlan-profileschema-keymaterial-sharedkey-element">keyMaterial</a> element of the profile returned in the buffer pointed to by the   <i>pstrProfileXml</i> parameter. No error is returned if the calling thread lacks the required permissions. <p class="note">By default, the <a href="https://docs.microsoft.com/windows/desktop/NativeWiFi/wlan-profileschema-keymaterial-sharedkey-element">keyMaterial</a> element returned in the profile pointed to by the <i>pstrProfileXml</i> is encrypted.   If your process runs in the context of the LocalSystem account on the same computer, then you can unencrypt key material by calling the <a href="https://docs.microsoft.com/windows/desktop/api/dpapi/nf-dpapi-cryptunprotectdata">CryptUnprotectData</a> function.</para>
    /// <para><b>Windows Server 2008 and Windows Vista:  </b>The <a href="https://docs.microsoft.com/windows/desktop/NativeWiFi/wlan-profileschema-keymaterial-sharedkey-element">keyMaterial</a> element returned in the profile schema pointed to by the <i>pstrProfileXml</i> is always encrypted.  If your process runs in the context of the LocalSystem account, then you can unencrypt key material by calling the <a href="https://docs.microsoft.com/windows/desktop/api/dpapi/nf-dpapi-cryptunprotectdata">CryptUnprotectData</a> function. <b>Windows XP with SP3 and Wireless LAN API for Windows XP with SP2:  </b>The key material is never encrypted.</para>
    /// <para><see href="https://learn.microsoft.com/windows/win32/api/wlanapi/nf-wlanapi-wlangetprofile#">Read more on docs.microsoft.com</see>.</para>
    /// </remarks>
    [DllImport("wlanapi.dll", ExactSpelling = true)]
    [DefaultDllImportSearchPaths(DllImportSearchPath.System32)]
    [SupportedOSPlatform("windows6.0.6000")]
    public static extern unsafe uint WlanGetProfile(winmdroot.Foundation.HANDLE hClientHandle, global::System.Guid* pInterfaceGuid, winmdroot.Foundation.PCWSTR strProfileName, [Optional] void* pReserved, winmdroot.Foundation.PWSTR* pstrProfileXml, [Optional] uint* pdwFlags, [Optional] uint* pdwGrantedAccess);
}

}


### Context

- CsWin32 version: [`0.3.106`]
- Target Framework: [`net8.0-windows7.0`]
AArnott commented 3 weeks ago

Thank you for the feedback.

Duplicate of #1183.