From the Microsoft Documentation:
DWORD WINAPI WlanHostedNetworkSetProperty(
_In_ HANDLE hClientHandle,
_In_ WLAN_HOSTED_NETWORK_OPCODE OpCode,
_In_ DWORD dwDataSize,
_In_ PVOID pvData,
_Out_opt_ PWLAN_HOSTED_NETWORK_REASON pFailReason,
_Reserved_ PVOID pvReserved
);
My implementation
[DllImport("Wlanapi.dll", EntryPoint = "WlanHostedNetworkSetProperty")]
public static extern uint WlanHostedNetworkSetProperty(
IntPtr hClientHandle,
WLAN_HOSTED_NETWORK_OPCODE OpCode,
uint dwDataSize,
IntPtr pvData,
[Out] out WLAN_HOSTED_NETWORK_REASON pFailReason,
IntPtr pReserved
);
This works fine if I am only trying to enable or disable Wlan. However when I try to set the ssid and the numbers of peers I am running into an error because pvData needs to be a pointer to the following struct:
From Microsoft Documentation:
typedef struct _WLAN_HOSTED_NETWORK_CONNECTION_SETTINGS {
DOT11_SSID hostedNetworkSSID;
DWORD dwMaxNumberOfPeers;
} WLAN_HOSTED_NETWORK_CONNECTION_SETTINGS, *PWLAN_HOSTED_NETWORK_CONNECTION_SETTINGS;
and
typedef struct _DOT11_SSID {
ULONG uSSIDLength;
UCHAR ucSSID[DOT11_SSID_MAX_LENGTH];
} DOT11_SSID, *PDOT11_SSID;
This is my implementation of both structures:
public struct WLAN_HOSTED_NETWORK_CONNECTION_SETTINGS
{
public DOT11_SSID hostedNetworkSSID;
public UInt32 dwMaxNumberOfPeers;
}
public struct DOT11_SSID
{
public UInt32 uSSIDLength;
public byte[] ucSSID;
}
Finally, this is how I am making the call:
APCreator.WLAN_HOSTED_NETWORK_CONNECTION_SETTINGS networkSetting = new APCreator.WLAN_HOSTED_NETWORK_CONNECTION_SETTINGS();
networkSetting.dwMaxNumberOfPeers = 5;
networkSetting.hostedNetworkSSID = new APCreator.DOT11_SSID();
networkSetting.hostedNetworkSSID.ucSSID = new byte[10];
//Populate ucSSID with network name
networkSetting.hostedNetworkSSID.uSSIDLength = 10;
int size = Marshal.SizeOf(networkSetting);
IntPtr pNetworkSetting = Marshal.AllocHGlobal(size);
Marshal.StructureToPtr(networkSetting, pNetworkSetting, true);
APCreator.WlanHostedNetworkSetProperty(HANDLE, APCreator.WLAN_HOSTED_NETWORK_OPCODE.wlan_hosted_network_opcode_connection_settings, (uint)size, pNetworkSetting, out ReasonEnum, Nill).ToString();
Error reason returns with: wlan_hosted_network_reason_isufficient_resources
The question is: How to set up those structures?