tomsell has asked for the wisdom of the Perl Monks concerning the following question:
I'm trying to automate connecting to a WiFi network by adding WlanConnect() to the splendid Win32::Wlan::API. System is a Win XP SP3 box and Win32::Wlan::API works flawlessly.
Here's what I've got so far, modeled after the existing code:
sub WlanConnect { croak "Wlan functions are not available" unless $wlan_available; my ($handle, $guuid, $profilename, $ssid) = @_; # possibly overkill, a pDot11Ssid = 0 should suffice my $pDot11Ssid = Win32::API::Struct->new('DOT11_SSID'); $pDot11Ssid->{uSSIDLength} = length $ssid; $pDot11Ssid->{ucSSID} = $ssid; my $Wlan_connection_parameters = Win32::API::Struct->new('WLAN_CON +NECTION_PARAMETERS'); $Wlan_connection_parameters->{wlanConnectionMode} = 0; $Wlan_connection_parameters->{strProfile} = $profilename; $Wlan_connection_parameters->{pDot11Ssid} = $pDot11Ssid; $Wlan_connection_parameters->{pDesiredBssidList} = 0; $Wlan_connection_parameters->{dot11BssType} = 3; $Wlan_connection_parameters->{dwFlags} = 0; $API{ WlanConnect }->Call($handle, $guuid, $Wlan_connection_parame +ters, 0) == 0 or die "$^E"; };
$profilename is an UTF-16LE encoded string while $ssid is just a perl string. The profile named by $profilename was freshly created and WlanSetProfile()'d properly (I can connect manually; WlanSetProfile() added by me).
WLAN_CONNECTION_PARAMETERS ist typedef'd as:
Win32::API::Struct->typedef('WLAN_CONNECTION_PARAMETERS', qw( WLAN_CONNECTION_MODE wlanConnectionMode; LPCWSTR strProfile; PDOT11_SSID pDot11Ssid; PDOT11_BSSID_LIST pDesiredBssidList; DOT11_BSS_TYPE dot11BssType; DWORD dwFlags; ));
while DOT11_SSID (possibly unnecessarily) typedef'd as
Win32::API::Struct->typedef ('DOT11_SSID', qw( ULONG uSSIDLength; UCHAR ucSSID; ));
Well, the code does not connect and referencing the Call line, $^E contains:
Any idea what is missing or where things go wrong?An attempt was made to reference a token that does not exist at...
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Adding WlanConnect() to Win32::Wlan::API
by Corion (Patriarch) on Jun 26, 2012 at 17:52 UTC | |
by tomsell (Acolyte) on Jun 26, 2012 at 19:53 UTC | |
by tye (Sage) on Jun 26, 2012 at 20:06 UTC | |
by tomsell (Acolyte) on Jun 26, 2012 at 20:42 UTC | |
by tye (Sage) on Jun 26, 2012 at 20:46 UTC | |
by bulk88 (Priest) on Jun 26, 2012 at 23:47 UTC | |
by tomsell (Acolyte) on Jun 27, 2012 at 08:32 UTC | |
by bulk88 (Priest) on Jun 27, 2012 at 13:48 UTC | |
| |
|
Re: Adding WlanConnect() to Win32::Wlan::API ($^E)
by tye (Sage) on Jun 26, 2012 at 17:58 UTC |