[29276] in Perl-Users-Digest
Perl-Users Digest, Issue: 520 Volume: 11
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Jun 15 14:14:33 2007
Date: Fri, 15 Jun 2007 11:14:18 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Fri, 15 Jun 2007 Volume: 11 Number: 520
Today's topics:
Re: Win32: How to quit perl script during log off autom <petersob@gmx.net>
Re: Win32: How to quit perl script during log off autom <rprp@gmx.net>
Re: Win32: How to quit perl script during log off autom <lambik@kieffer.nl>
Re: Win32: How to quit perl script during log off autom <petersob@gmx.net>
Re: Win32: How to quit perl script during log off autom <petersob@gmx.net>
Re: Writing row at a time in Excel using OLE <jgibson@mail.arc.nasa.gov>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Fri, 15 Jun 2007 16:00:20 +0000 (UTC)
From: Peter Sobisch <petersob@gmx.net>
Subject: Re: Win32: How to quit perl script during log off automatically ?
Message-Id: <f4ud2k$be7$1@online.de>
Thomas Kratz <ThomasKratz@REMOVEwebCAPS.de> schrieb:
> Peter Sobisch wrote:
>> ----snip---
>> use Win32::API;
>> use Win32::API::Callback;
>>
>> my $callback = Win32::API::Callback->new(
>> sub { my($a, $b) = @_; return $a+$b; },
>> "NN", "N",
>> );
>> ----snap---
>>
>> gives the SEGFAULT and following message written to the console:
>> "Free to wrong pool 15e2660 not e58b2660, <DATA> line 164."
>
> Your Win32::API::Callback seems to be broken. The code runs without
> errors on my 5.8.8 (windows non ActiveState). Where did you install it from?
I've also ActiveState 5.8.8 Build 817 installed, I got the Win32::API-0.46 from
CPAN and installed it by using Bloodshed Dev-C++ 4.9.9.2 and nmake1.5.
Evereything went well, except the Callback test, which has failed.
Nevertheless I did "nmake install" in order to use the other
Win32::API functionality.
I run Windows XP Pro SP 2.
Regards,
Peter
------------------------------
Date: Fri, 15 Jun 2007 18:04:33 +0200
From: Reinhard Pagitsch <rprp@gmx.net>
Subject: Re: Win32: How to quit perl script during log off automatically ?
Message-Id: <4672b892$0$90264$14726298@news.sunsite.dk>
Peter Sobisch wrote:
> Reinhard Pagitsch <rprp@gmx.net> schrieb:
>>>>> Every time I try to shutdown or log off, pop-up is comming up with
>>>>> "application doesn't response" and expecting to kill by clicking a
>>>>> button -> very dirty thing :-/
>>>>> So, I tried to catch WM_QUERYENDSESSION (using Win32::GUI::Hook), but no
>>>> You should reveive a WM_CLOSE according to Bill.
>>> not really, I'm affraid windows doesn't sent neither WM_CLOSE nor
>>> WM_QUIT because of the same reason of not sending WM_QUERYENDSESSION.
>>
>> Have you also read the MSDN documentation about SetConsoleCtrlHandler?
>> The last paragraph say:
>>
>> The system generates CTRL_CLOSE_EVENT, CTRL_LOGOFF_EVENT, and
>> CTRL_SHUTDOWN_EVENT signals when the user closes the console, logs off,
>> or shuts down the system so that the process has an opportunity to clean
>> up before termination. Console functions, or any C run-time functions
>> that call console functions, may not work reliably during processing of
>> any of the three signals mentioned previously. The reason is that some
>> or all of the internal console cleanup routines may have been called
>> before executing the process signal handler.
>
> this is the thing I wanted to do but the Win32::API::Callback doesn't
> work :-(
> But I have a small workaround for now, I wrote a C module where I
> register a C-written-callback where I run ExitProcess().
> It's dirty to me, because I have no possibility to clean up or do
> something else, but, the process really ends on logoff.
>
> Neverthereless, I still interesting in Win32::API::Callback to get it
> work, because it would be very useful feature in Win32 enviroment.
>
> I tried to write something similars, but how I mentioned above, I've a
> problem to call a perl routine from the C-callback, not even the
> simplest one from perlcall manpage worked, I got SEGFAULT every time.
>
> I'm not sure, but could it be a problem calling the call_pv() or call_sv()
> from the callback which is launching in another thread ?
>
> MS says the CtrlHandler will be called in separated thread, see
> the "HandlerRoutine" in MSDN:
>
> ------snip------
> Because the system creates a new thread in the process to execute the
> handler function, it is possible that the handler function will be
> terminated by another thread in the process. Be sure to synchronize
> threads in the process with the thread for the handler function.
> ------snap------
>
>> Can you send me the code you are using, maybe I can find it out why the
>> Win32::API::Callback Module crashes.
>
> just a simple define of a callback:
>
> ----snip---
> use Win32::API;
> use Win32::API::Callback;
>
> my $callback = Win32::API::Callback->new(
> sub { my($a, $b) = @_; return $a+$b; },
> "NN", "N",
> );
> ----snap---
>
> gives the SEGFAULT and following message written to the console:
> "Free to wrong pool 15e2660 not e58b2660, <DATA> line 164."
>
>
As Thomas wrote, the Module is broken. I assume to remove it and install
it again. In my environment, Activestate 5.8.8 on XP Sp2, this code
works perfect.
You can download it from http://www.bribes.org/perl/ppm/ (30-Jan-2007)
or Activestate.
Here you can find a list of PPM repositories:
http://win32.perl.org/wiki/index.php?title=PPM_Repositories
regards,
Reinhard
--
PM Mails an rpirpag <at> gmx dot at
------------------------------
Date: Fri, 15 Jun 2007 18:23:24 +0200
From: "Lambik" <lambik@kieffer.nl>
Subject: Re: Win32: How to quit perl script during log off automatically ?
Message-Id: <4672bcb3$0$37713$5fc3050@dreader2.news.tiscali.nl>
"Peter Sobisch" <petersob@gmx.net> wrote in message
news:f4ogqo$uun$1@online.de...
>
> Lambik <lambik@kieffer.nl> schrieb:
> >> on Unix its a simplest thing, perl do it for me or I can set $SIG{HUP}
:-)
> >> but, how can I do this in Windows ?
> >>
> >> Every time I try to shutdown or log off, pop-up is comming up with
> >> "application doesn't response" and expecting to kill by clicking a
> >> button -> very dirty thing :-/
> >>
> >> So, I tried to catch WM_QUERYENDSESSION (using Win32::GUI::Hook), but
no
> >
> > You should reveive a WM_CLOSE according to Bill.
>
>
> not really, I'm affraid windows doesn't sent neither WM_CLOSE nor
> WM_QUIT because of the same reason of not sending WM_QUERYENDSESSION.
>
I hate to state the obvious, but I recon you considered making it a windows
program using win32::gui. It has a getMessage
http://dada.perl.it/gui_docs/Win32_GUI.html#GetMessage_MIN_MAX_
And you could use threads adding a thread which listens to a c program. But
I guess you've already done that. There is always the possibility to make
your own XS module.
#include <windows.h>
#include <stdio.h>
BOOL CtrlHandler( DWORD fdwCtrlType )
{
switch( fdwCtrlType )
{
case CTRL_LOGOFF_EVENT:
Beep( 1000, 200 );
printf( "Ctrl-Logoff event\n\n" );
return FALSE;
case CTRL_SHUTDOWN_EVENT:
Beep( 750, 500 );
printf( "Ctrl-Shutdown event\n\n" );
return FALSE;
default:
return FALSE;
}
}
void main( void )
{
if( SetConsoleCtrlHandler( (PHANDLER_ROUTINE) CtrlHandler, TRUE ) )
{
while( 1 ){ }
}
else
printf( "\nERROR: Could not set control handler");
}
------------------------------
Date: Fri, 15 Jun 2007 17:36:57 +0000 (UTC)
From: Peter Sobisch <petersob@gmx.net>
Subject: Re: Win32: How to quit perl script during log off automatically ?
Message-Id: <f4uinp$k0c$1@online.de>
Reinhard Pagitsch <rprp@gmx.net> schrieb:
> Peter Sobisch wrote:
>> Reinhard Pagitsch <rprp@gmx.net> schrieb:
>>>>>> Every time I try to shutdown or log off, pop-up is comming up with
>>>>>> "application doesn't response" and expecting to kill by clicking a
>>>>>> button -> very dirty thing :-/
>>>>>> So, I tried to catch WM_QUERYENDSESSION (using Win32::GUI::Hook), but no
>>>>> You should reveive a WM_CLOSE according to Bill.
>>>> not really, I'm affraid windows doesn't sent neither WM_CLOSE nor
>>>> WM_QUIT because of the same reason of not sending WM_QUERYENDSESSION.
>>>
>>> Have you also read the MSDN documentation about SetConsoleCtrlHandler?
>>> The last paragraph say:
>>>
>>> The system generates CTRL_CLOSE_EVENT, CTRL_LOGOFF_EVENT, and
>>> CTRL_SHUTDOWN_EVENT signals when the user closes the console, logs off,
>>> or shuts down the system so that the process has an opportunity to clean
>>> up before termination. Console functions, or any C run-time functions
>>> that call console functions, may not work reliably during processing of
>>> any of the three signals mentioned previously. The reason is that some
>>> or all of the internal console cleanup routines may have been called
>>> before executing the process signal handler.
>>
>> this is the thing I wanted to do but the Win32::API::Callback doesn't
>> work :-(
>> But I have a small workaround for now, I wrote a C module where I
>> register a C-written-callback where I run ExitProcess().
>> It's dirty to me, because I have no possibility to clean up or do
>> something else, but, the process really ends on logoff.
>>
>> Neverthereless, I still interesting in Win32::API::Callback to get it
>> work, because it would be very useful feature in Win32 enviroment.
>>
>> I tried to write something similars, but how I mentioned above, I've a
>> problem to call a perl routine from the C-callback, not even the
>> simplest one from perlcall manpage worked, I got SEGFAULT every time.
>>
>> I'm not sure, but could it be a problem calling the call_pv() or call_sv()
>> from the callback which is launching in another thread ?
>>
>> [...]
>>
>>> Can you send me the code you are using, maybe I can find it out why the
>>> Win32::API::Callback Module crashes.
>>
>> just a simple define of a callback:
>>
>> ----snip---
>> use Win32::API;
>> use Win32::API::Callback;
>>
>> my $callback = Win32::API::Callback->new(
>> sub { my($a, $b) = @_; return $a+$b; },
>> "NN", "N",
>> );
>> ----snap---
>>
>> gives the SEGFAULT and following message written to the console:
>> "Free to wrong pool 15e2660 not e58b2660, <DATA> line 164."
>>
>
> As Thomas wrote, the Module is broken. I assume to remove it and install
> it again. In my environment, Activestate 5.8.8 on XP Sp2, this code
> works perfect.
>
> You can download it from http://www.bribes.org/perl/ppm/ (30-Jan-2007)
> or Activestate.
>
> Here you can find a list of PPM repositories:
> http://win32.perl.org/wiki/index.php?title=PPM_Repositories
>
thanks for the link !
Module doesn't crash anymore :-)
now I only one step further, but the call I wanted to do fails now
in calling the callback, here the code:
------------------------snip-----------------
use strict;
use Win32::API;
use Win32::API::Callback;
sub handler {
my $type = shift;
print "RECEIVED SIGNAL: $type\n",;
return 1;
}
my $callback =
Win32::API::Callback->new(\&handler, "I", "I" );
my $function =
Win32::API->new('kernel32','SetConsoleCtrlHandler','KI','I');
$function->Call($callback,1);
my $i= 0;
while ($i<2000) {
print ++$i,"\n";
sleep(1); # in this loop press Ctrl+C
}
-----------------------snap----------------------
it crashs now not by defining the callback but
after I press "Ctrl+C" inside the loop :-/
If I do this in XSUB it seems to work, but only to do ExitProcess(),
But I'd like to be able to call a callback.
For comparison here comes my working XS code (with ExitProcess()):
-----------snip------------------
#include "EXTERN.h"
#include "perl.h"
#include "XSUB.h"
#include "ppport.h"
#include "windows.h"
#include "wincon.h"
#define MAX_EVENT CTRL_SHUTDOWN_EVENT
int event[7] = { 0,0,0,0,0,0,0 };
BOOL WINAPI CtrlHandler(DWORD type) {
printf("received: %d\n",type);
if (type > MAX_EVENT)
return FALSE;
if (event[type])
ExitProcess(0);
return FALSE;
}
MODULE = Logoff PACKAGE = Logoff
int
LogoffOnEvent(ev, logoff)
int ev
int logoff
CODE:
int rv;
if (ev > MAX_EVENT) {
rv = -1;
} else {
event[ev] = logoff;
rv = SetConsoleCtrlHandler(CtrlHandler,TRUE);
}
RETVAL = rv;
OUTPUT:
RETVAL
-----------snap------------------
to test this module I use this simple piece of perl code:
-----------snip-----------------
use Logoff;
Logoff::LogoffOnEvent(5,1); # quits after Logoff
Logoff::LogoffOnEvent(0,1); # quits after Ctrl+C
do {
print "sleeping...$i\n"; # try to logoff or Ctrl+C
sleep(1);
} until $i > 10000;
------------snap----------------
the big disadvantage of this is that I have no possibility to clean up
my perl code.
As I wrote before, I tried already to call a perl callback in
CtrlHandler using call_sv() or call_pv(), without any success,
this ends every time with segfault calling the perl code,
the same thing as the perl variant using Win32::API::Callback
also does (ofcourse after I re-installed the Win32::API-0.46
module from http://www.bribes.org/perl/ppm/).
Are there a more restrictions inside a CtrlHandler which disallow to
do something like call a perl callback ?
regards
Peter
------------------------------
Date: Fri, 15 Jun 2007 17:45:08 +0000 (UTC)
From: Peter Sobisch <petersob@gmx.net>
Subject: Re: Win32: How to quit perl script during log off automatically ?
Message-Id: <f4uj73$k0c$2@online.de>
Lambik <lambik@kieffer.nl> schrieb:
> "Peter Sobisch" <petersob@gmx.net> wrote in message
> news:f4ogqo$uun$1@online.de...
>>
>> Lambik <lambik@kieffer.nl> schrieb:
>> >> on Unix its a simplest thing, perl do it for me or I can set $SIG{HUP}
>:-)
>> >> but, how can I do this in Windows ?
>> >>
>> >> Every time I try to shutdown or log off, pop-up is comming up with
>> >> "application doesn't response" and expecting to kill by clicking a
>> >> button -> very dirty thing :-/
>> >>
>> >> So, I tried to catch WM_QUERYENDSESSION (using Win32::GUI::Hook), but
> no
>> > You should reveive a WM_CLOSE according to Bill.
>> not really, I'm affraid windows doesn't sent neither WM_CLOSE nor
>> WM_QUIT because of the same reason of not sending WM_QUERYENDSESSION.
> I hate to state the obvious, but I recon you considered making it a windows
> program using win32::gui. It has a getMessage
> http://dada.perl.it/gui_docs/Win32_GUI.html#GetMessage_MIN_MAX_
>
> And you could use threads adding a thread which listens to a c program. But
> I guess you've already done that. There is always the possibility to make
> your own XS module.
>
> #include <windows.h>
> #include <stdio.h>
>
> BOOL CtrlHandler( DWORD fdwCtrlType )
> {
> switch( fdwCtrlType )
> {
> case CTRL_LOGOFF_EVENT:
> Beep( 1000, 200 );
> printf( "Ctrl-Logoff event\n\n" );
> return FALSE;
>
> case CTRL_SHUTDOWN_EVENT:
> Beep( 750, 500 );
> printf( "Ctrl-Shutdown event\n\n" );
> return FALSE;
>
> default:
> return FALSE;
> }
> }
>
> void main( void )
> {
> if( SetConsoleCtrlHandler( (PHANDLER_ROUTINE) CtrlHandler, TRUE ) )
> {
> while( 1 ){ }
> }
> else
> printf( "\nERROR: Could not set control handler");
> }
thas is easy ! This works for me already inside a XS to do ExitProcess(),
but my problem is: I'd like to do more than "beep" and "printf".
Please try to call perl code inside CtrlHandler and tellme how :-)
Actually I expected I can do this using Win32::API::Callback(),
but I can't get it work :-( See my another posting.
Regards
Peter
------------------------------
Date: Fri, 15 Jun 2007 09:24:55 -0700
From: Jim Gibson <jgibson@mail.arc.nasa.gov>
Subject: Re: Writing row at a time in Excel using OLE
Message-Id: <150620070924558764%jgibson@mail.arc.nasa.gov>
In article <1181843391.577838.285570@j4g2000prf.googlegroups.com>, Ash
<ashishrai@gmail.com> wrote:
> Hi!
>
> I need to write a row at a time or a whole sheet at a time, anything
> faster than one cell at a time in Excel sheet using Win32::OLE. Can
> anyone help me?
>
> Spreadsheet::WriteExcel module have functions for writing row at a
> time but I need to modify existing Excel file and the module does not
> allow that.
Check out the module Spreadsheet::ParseExcel::SaveParser, which claims
to be able to modify an existing spreadsheet file (I have not used it).
<http://search.cpan.org/~szabgab/Spreadsheet-ParseExcel-0.32/lib/Spreads
heet/ParseExcel/SaveParser.pm>
Posted Via Usenet.com Premium Usenet Newsgroup Services
----------------------------------------------------------
** SPEED ** RETENTION ** COMPLETION ** ANONYMITY **
----------------------------------------------------------
http://www.usenet.com
------------------------------
Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 6 Apr 01)
Message-Id: <null>
Administrivia:
#The Perl-Users Digest is a retransmission of the USENET newsgroup
#comp.lang.perl.misc. For subscription or unsubscription requests, send
#the single line:
#
# subscribe perl-users
#or:
# unsubscribe perl-users
#
#to almanac@ruby.oce.orst.edu.
NOTE: due to the current flood of worm email banging on ruby, the smtp
server on ruby has been shut off until further notice.
To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.
#To request back copies (available for a week or so), send your request
#to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
#where x is the volume number and y is the issue number.
#For other requests pertaining to the digest, send mail to
#perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
#sending perl questions to the -request address, I don't have time to
#answer them even if I did know the answer.
------------------------------
End of Perl-Users Digest V11 Issue 520
**************************************