The code is below to test Win32::API with perl2exe: #========================================================== $| = 1; use CGI::Carp; use Carp::Heavy; #========================================================== use threads; use threads::shared; use Thread::Running; use LWP::UserAgent; use attributes; use WIn32::API; share %Result; share %Done; #========================================================== use Win32::GUI; $MW = new Win32::GUI::Window( -title => 'Test', -left => 100, -top => 100, -width => 400, -height => 200, -name => 'MainWindow', -visible => 1, );
$PrintMsg = $MW->AddLabel( -text => "Processing:", -name => "ProcessingLabel", -left => 30, -top => 30, -width => 290, -height => 20, -foreground => 0, -visible=> 1, ); #---------------------------------------- &StartThreads; $MW->Show(); Win32::GUI::Dialog; #---------------------------------------- sub MainWindow_Terminate { return -1; } #========================================================== sub StartThreads{ my ($x, @x, @url); $x = 0; undef @x; @url = ('http://search.cpan.org/', 'http://yahoo.com/', 'http://mewsoft.com/', 'http://ayna.com/', 'http://arabikx.com/', 'http://maktoob.com/', 'http://masrawy.com/', 'http://ajeeb.com/', 'http://egypt.com/', 'http://search.com/'); undef %Thread; undef %Done; undef %Result; for $x(0..9) { $y[0] = $x; $y[1] = $url[$x]; $Done{$x} = 2; $Thread{$x} = threads->new(\&get_url, @y); $Thread{$x}->detach(); $PrintMsg->Text("Created thread $x..."); } #$Thread{0}->join; #sleep 1 until threads->tojoin; #while (! threads->tojoin) {print ".";sleep 1;} # This created the error The memory can not be "read". #$_->join foreach threads->tojoin; # join all joinable threads while (1) { while (my($k, $v) = each %Done) { if ($v==1) { $PrintMsg->Text("Finished Thread $k..."); delete $Done{$k}; } } my $k = keys %Done; if (!$k) {last;} Win32::GUI::DoEvents(); }; $PrintMsg->Text("Finished All Threads..."); return 1; } #========================================================== sub get_url{ my ($id, $url) = @_; my ($text); my $ua = LWP::UserAgent->new; my $response = $ua->get($url); if ($response->is_success) { $text = $response->content; # or whatever #print STDERR "Success URL: $url \n"; } else { #print STDERR "Error URL: $url \n"; $text = $response->status_line; } #return $text; $Result{$id} = $text; $Done{$id} = 1; #return "$id\n"; } #==========================================================