[32508] in Perl-Users-Digest
Perl-Users Digest, Issue: 3773 Volume: 11
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sat Sep 8 00:09:19 2012
Date: Fri, 7 Sep 2012 21:09:03 -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, 7 Sep 2012 Volume: 11 Number: 3773
Today's topics:
Re: Win32::API use Pointer to struct <Peter.Arnhold@web.de>
Re: Win32::API use Pointer to struct (Heinrich Mislik)
Re: Win32::API use Pointer to struct <Peter.Arnhold@web.de>
Re: Win32::API use Pointer to struct <rweikusat@mssgmbh.com>
Re: Win32::API use Pointer to struct <rweikusat@mssgmbh.com>
Re: Win32::API use Pointer to struct <Peter.Arnhold@web.de>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Fri, 07 Sep 2012 04:47:47 +0200
From: Peter Arnhold <Peter.Arnhold@web.de>
Subject: Re: Win32::API use Pointer to struct
Message-Id: <50496053$0$6567$3ca0ca56@newsspool3.vodafone-ip.de>
Am 06.09.2012 23:08, schrieb Rainer Weikusat:
> Peter Arnhold <Peter.Arnhold@web.de> writes:
>> how can I correctly 'unpack' $SessionInfo?:
>>
>> use Win32::API;
>>
>> my $WTSOpenServer = new Win32::API("wtsapi32.dll", "WTSOpenServer",[P],N);
>> my $hServer = $WTSOpenServer->Call('');
>> my $SessionInfo = pack 'L4', 0;
>> my $Count = pack 'C', 0;
>>
>> my $WTSEnumerateSessions = new Win32::API(
>> 'wtsapi32.dll', 'WTSEnumerateSessions',[qw(N N N P P)],'I'
>> );
>> $WTSEnumerateSessions->Call($hServer,0,1,$SessionInfo,$Count);
>
> Judgeging from
>
> http://msdn.microsoft.com/en-us/library/windows/desktop/aa383833%28v=vs.85%29.aspx
>
> and the Win32::API documentation, the sizes of the buffers you are
> passing are wrong: The second should be four bytes (DWORD), not 1, and
> the first would need to be large enough to accommodate the number of
> structures which will be returned, however this is supposed to be
> determined. According to
>
> http://msdn.microsoft.com/en-us/library/windows/desktop/aa383864%28v=vs.85%29.aspx
>
> the 'bare' size of such a structure should be 12 bytes, not 16 and 16
> (4 times 4 bytes) is certainly to small to hold two structures.
>
ACK. Bad example. I know this msdn sites. I followed your advice but no other
result. $Count is 2 - correct, $SessionInfo is still no _WTS_SESSION_INFO.
------------------------------
Date: Fri, 7 Sep 2012 09:23:49 +0000 (UTC)
From: Heinrich.Mislik@univie.ac.at (Heinrich Mislik)
Subject: Re: Win32::API use Pointer to struct
Message-Id: <k2cef5$epv$1@news.albasani.net>
In article <50490bc7$0$6570$3ca0ca56@newsspool4.vodafone-ip.de>, Peter.Arnhold@web.de says...
>how can I correctly 'unpack' $SessionInfo?:
Can't you use Win32::API::Struct? Much easier than using pack/unpack.
Cheers
Heinrich
--
Heinrich Mislik
Zentraler Informatikdienst der Universitaet Wien
A-1010 Wien, Universitaetsstrasse 7
Tel.: (+43 1) 4277-14056, Fax: (+43 1) 4277-9140
------------------------------
Date: Fri, 07 Sep 2012 12:08:15 +0200
From: Peter Arnhold <Peter.Arnhold@web.de>
Subject: Re: Win32::API use Pointer to struct
Message-Id: <5049c78f$0$6581$3ca0ca56@newsspool3.vodafone-ip.de>
Am 07.09.2012 11:23, schrieb Heinrich Mislik:
> In article <50490bc7$0$6570$3ca0ca56@newsspool4.vodafone-ip.de>, Peter.Arnhold@web.de says...
>
>> how can I correctly 'unpack' $SessionInfo?:
>
> Can't you use Win32::API::Struct? Much easier than using pack/unpack.
But how?
I found out this, triggered by Rainer's thoughts:
$WTSEnumerateSessions->Call($hServer,0,1,$SessionInfo,$Count);
$Count = unpack 'I', $Count;
$SessionInfo = unpack 'P'.(12 x $Count), $SessionInfo;
foreach my $pos ( 0 .. $Count-1 ) {
my($id,$p,$state) = unpack '@'.($pos*12).' LLL', $SessionInfo;
print "$id => $state => ", unpack('p', pack('L', $p)), "\n";
}
0 => 4 => Services
2 => 0 => Console
This is not really nice but works. No idea how to handle $SessionInfo by
Win32::API::Struct. Too much Win32 ;-)
Gruß,
Peter
------------------------------
Date: Fri, 07 Sep 2012 11:41:51 +0100
From: Rainer Weikusat <rweikusat@mssgmbh.com>
Subject: Re: Win32::API use Pointer to struct
Message-Id: <87bohixggg.fsf@sapphire.mobileactivedefense.com>
Rainer Weikusat <rweikusat@mssgmbh.com> writes:
> Peter Arnhold <Peter.Arnhold@web.de> writes:
>> how can I correctly 'unpack' $SessionInfo?:
>>
>> use Win32::API;
>>
>> my $WTSOpenServer = new Win32::API("wtsapi32.dll", "WTSOpenServer",[P],N);
>> my $hServer = $WTSOpenServer->Call('');
>> my $SessionInfo = pack 'L4', 0;
>> my $Count = pack 'C', 0;
>>
>> my $WTSEnumerateSessions = new Win32::API(
>> 'wtsapi32.dll', 'WTSEnumerateSessions',[qw(N N N P P)],'I'
>> );
>> $WTSEnumerateSessions->Call($hServer,0,1,$SessionInfo,$Count);
[...]
> and the first would need to be large enough to accommodate the number of
> structures which will be returned, however this is supposed to be
> determined.
To have this explicitly: I misread this. The second argument needs to
be a pointer to a pointer where the address of the structure array is
supposed to be stored. This can then be unpacked in the way Peter
showed in his posting in the other subthread.
------------------------------
Date: Fri, 07 Sep 2012 11:47:54 +0100
From: Rainer Weikusat <rweikusat@mssgmbh.com>
Subject: Re: Win32::API use Pointer to struct
Message-Id: <877gs6xg6d.fsf@sapphire.mobileactivedefense.com>
Peter Arnhold <Peter.Arnhold@web.de> writes:
[...]
> foreach my $pos ( 0 .. $Count-1 ) {
> my($id,$p,$state) = unpack '@'.($pos*12).' LLL', $SessionInfo;
> print "$id => $state => ", unpack('p', pack('L', $p)), "\n";
> }
>
> 0 => 4 => Services
> 2 => 0 => Console
>
> This is not really nice but works.
Based on some experiments with 'manually' created structures of this
form, it should be possible to use LpL for unpacking such a structure
directly:
--------------
$string = 'Elfriede';
$struct = pack('LpL', 4, $string, 5);
($id, $name, $state) = unpack('LpL', $struct);
print("$id, $name, $state\n");
------------------------------
Date: Fri, 07 Sep 2012 13:26:01 +0200
From: Peter Arnhold <Peter.Arnhold@web.de>
Subject: Re: Win32::API use Pointer to struct
Message-Id: <5049d9c8$0$6580$3ca0ca56@newsspool3.vodafone-ip.de>
Am 07.09.2012 12:47, schrieb Rainer Weikusat:
> Peter Arnhold <Peter.Arnhold@web.de> writes:
>
> [...]
>
>> foreach my $pos ( 0 .. $Count-1 ) {
>> my($id,$p,$state) = unpack '@'.($pos*12).' LLL', $SessionInfo;
>> print "$id => $state => ", unpack('p', pack('L', $p)), "\n";
>> }
>>
>> 0 => 4 => Services
>> 2 => 0 => Console
>>
>> This is not really nice but works.
>
> Based on some experiments with 'manually' created structures of this
> form, it should be possible to use LpL for unpacking such a structure
> directly:
>
> --------------
> $string = 'Elfriede';
> $struct = pack('LpL', 4, $string, 5);
> ($id, $name, $state) = unpack('LpL', $struct);
> print("$id, $name, $state\n");
Of course yes. THX.
------------------------------
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:
To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.
Back issues are available via anonymous ftp from
ftp://cil-www.oce.orst.edu/pub/perl/old-digests.
#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 3773
***************************************