如何在C#中调用本机Wifi功能,如此
DWORD WINAPI WlanHostedNetworkForceStart(
_In_ HANDLE hClientHandle,
_Out_opt_ PWLAN_HOSTED_NETWORK_REASON pFailReason,
_Reserved_ PVOID pvReserved
);
http://msdn.microsoft.com/en-us/library/windows/desktop/dd439488(v=vs.85).aspx
答案 0 :(得分:1)
您需要定义将使用的类型并声明方法。有关详细说明,请参阅Platform Invoke Tutorial。
为了帮助您入门,您需要WLAN_HOSTED_NETWORK_REASON
枚举:
public enum WLAN_HOSTED_NETWORK_REASON
{
wlan_hosted_network_reason_success = 0,
wlan_hosted_network_reason_unspecified,
wlan_hosted_network_reason_bad_parameters,
wlan_hosted_network_reason_service_shutting_down,
wlan_hosted_network_reason_insufficient_resources,
wlan_hosted_network_reason_elevation_required,
wlan_hosted_network_reason_read_only,
wlan_hosted_network_reason_persistence_failed,
wlan_hosted_network_reason_crypt_error,
wlan_hosted_network_reason_impersonation,
wlan_hosted_network_reason_stop_before_start,
wlan_hosted_network_reason_interface_available,
wlan_hosted_network_reason_interface_unavailable,
wlan_hosted_network_reason_miniport_stopped,
wlan_hosted_network_reason_miniport_started,
wlan_hosted_network_reason_incompatible_connection_started,
wlan_hosted_network_reason_incompatible_connection_stopped,
wlan_hosted_network_reason_user_action,
wlan_hosted_network_reason_client_abort,
wlan_hosted_network_reason_ap_start_failed,
wlan_hosted_network_reason_peer_arrived,
wlan_hosted_network_reason_peer_departed,
wlan_hosted_network_reason_peer_timeout,
wlan_hosted_network_reason_gp_denied,
wlan_hosted_network_reason_service_unavailable,
wlan_hosted_network_reason_device_change,
wlan_hosted_network_reason_properties_change,
wlan_hosted_network_reason_virtual_station_blocking_use,
wlan_hosted_network_reason_service_available_on_virtual_station
}
接下来,定义本机方法:
[DllImport("Wlanapi.dll", EntryPoint = "WlanHostedNetworkForceStart")]
public static extern uint WlanHostedNetworkForceStart(
IntPtr hClientHandle,
[Out] out WLAN_HOSTED_NETWORK_REASON pFailReason,
IntPtr pvReserved);
您只需在C#代码中的任何位置调用它:
WLAN_HOSTED_NETWORK_REASON failReason;
var result = WlanHostedNetworkForceStart(myClientHandle, out failReason, myReserved);