Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
Hi bulk88,

I've been trying to adopt your codes to mine and I get this error that there was an overflow every time I call sub add_job on run-time by pressing the Button A
*** unhandled exception in callback: *** Win32::API::Call: parameter 5 had a buffer overflow at (eval 18) + line 2. *** ignoring at pipecall.pl line 65.

this is my new code
#!/usr/bin/perl -w use strict; use Gtk2 '-init'; use Gtk2::Helper; use Data::Dumper; use FileHandle; use IPC::Open2; use Win32API::File; use Win32; use Win32::API; { my $api; die "PeekNamedPipe" if ! ($api= Win32::API::More->Import("kernel32", " BOOL PeekNamedPipe( HANDLE hNamedPipe, LPVOID lpBuffer, DWORD nBufferSize, LPDWORD lpBytesRead, LPDWORD lpTotalBytesAvail, LPDWORD lpBytesLeftThisMessage );")); } my $wfh = FileHandle->new(); my $rfh = FileHandle->new(); open2($rfh,$wfh,"C:\\Windows\\System32\\cmd.exe"); my $hnd = Win32API::File::FdGetOsFHandle($rfh->fileno()); #get Win32 k +ernel handle from Perl land if($hnd == Win32API::File::INVALID_HANDLE_VALUE()) { die "bad hnd"; } my $tag = Gtk2::Helper->add_watch($rfh, 'in',\&preview_call); my $window = Gtk2::Window->new(); $window->signal_connect("destroy",sub{Gtk2->main_quit();}); $window->set_size_request(300,300); my $hbox = Gtk2::HBox->new(); $window->add($hbox); my $button = Gtk2::Button->new("A"); $button->signal_connect('clicked'=>sub{ add_job(); }); $hbox->pack_start($button,1,1,0); $button = Gtk2::Button->new("B"); $button->signal_connect('clicked'=>sub{ print "i do nothing\n"; }); $hbox->pack_start($button,1,1,0); $window->show_all(); Gtk2->main(); sub preview_call { my $bRead = 0; my $bLeft = 0; my $bAvail = 0; my $ret = 0; my $buffer; $ret = PeekNamedPipe($hnd,undef,0,undef,$bAvail,undef); if(!$ret) { my $err = Win32::GetLastError(); die "PNP failed $err $^E"; } if($bAvail) { print "Available: $bAvail\n"; sysread($rfh,$buffer,1); print $buffer . "\n"; }else{ } return 1; } sub add_job { print $wfh "dir\n"; }
Mabuhay Civil Engineers! :D

In reply to Re^2: ActivePerl Gtk2::Helper Hangs by renegadex
in thread ActivePerl Gtk2::Helper Hangs by renegadex

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (6)
As of 2024-04-24 15:48 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found