Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re^10: Adding WlanConnect() to Win32::Wlan::API (structs no go?)

by bulk88 (Priest)
on Jun 28, 2012 at 02:48 UTC ( [id://978820]=note: print w/replies, xml ) Need Help??


in reply to Re^9: Adding WlanConnect() to Win32::Wlan::API (structs no go?)
in thread Adding WlanConnect() to Win32::Wlan::API

i got WlanConnect to work, here is your WlanConnect, it makes my wireless popup bubble come up, so it works
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('PDOT11_SSID'); #$pDot11Ssid->{uSSIDLength} = length $ssid; #$pDot11Ssid->{ucSSID} = $ssid; my $SSIDstruct = pack('LZ[32]',length $ssid, $ssid ); #not overflo +w checked my $Wlan_connection_parameters = pack('LPPJLL', 0, $profilename, $ +SSIDstruct, 0, 3, 0); #$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; my $reterr = $API{ WlanConnect }->Call($handle, $guuid, $Wlan_con +nection_parameters, 0); $reterr == 0 or die "WlanConnect return Error $reterr "; }
I also changed main for null safety and to work on my machine
sub main { $ARGV[0] = 'removed'; $ARGV[1] = 'removed'; die "USAGE: $0 PROFILENAME SSID\n" unless($ARGV[1]); my $profilename = $ARGV[0]; my $ssid = $ARGV[1]; my $wlan_handle = WlanOpenHandle(); my @interfaces = WlanEnumInterfaces($wlan_handle); my $wlan_guuid = $interfaces[0]->{guuid}; $profilename = encode('UTF-16LE', $profilename."\x00"); WlanConnect($wlan_handle, $wlan_guuid, $profilename, $ssid); }
I dont think my pack codes work on x64 BTW. Perhaps another monk can rewrite them to be portable, or you can just make another SOPW post.

Replies are listed 'Best First'.
Re^11: Adding WlanConnect() to Win32::Wlan::API (pack and go!)
by tomsell (Acolyte) on Jun 28, 2012 at 08:48 UTC

    Thanks for the rewrite! It makes sense.

    However. I have to report that perl.exe (ActiveState v5.8.8) dies with an exception when making the call to the native WlanConnect() and Windows pops up its error reporting applet. Well, it might be XP or it might be the adhoc network but I guess that's the end of the line.

    Update: SUCCESS! WlanConnect() connects.

    I had failed to re-adjust the signature. Must be:

    ['WlanConnect' => 'IPPI' => 'I']

    Thanks, bulk88!

      Likely, the exception comes from improperly (un)packing a parameter, or packing it with the wrong width. I would look close at the parameters and their values, and compare them to the C equivalents.

      This gives me a horrible idea - maybe Convert::Binary::C can be abused to generate pack templates for arbitrary structs, as it contains the necessary logic to invoke a C compiler for getting the struct (and alignment) information. A cursory glance doesn't show me the easy way to get a pack/unpack template pair from that, but likely there is a way...

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://978820]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others sharing their wisdom with the Monastery: (3)
As of 2024-04-18 22:49 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found