[32507] in Perl-Users-Digest
Perl-Users Digest, Issue: 3772 Volume: 11
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Sep 6 21:09:18 2012
Date: Thu, 6 Sep 2012 18:09:05 -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 Thu, 6 Sep 2012 Volume: 11 Number: 3772
Today's topics:
Win32::API use Pointer to struct <Peter.Arnhold@web.de>
Re: Win32::API use Pointer to struct <rweikusat@mssgmbh.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Thu, 06 Sep 2012 22:47:04 +0200
From: Peter Arnhold <Peter.Arnhold@web.de>
Subject: Win32::API use Pointer to struct
Message-Id: <50490bc7$0$6570$3ca0ca56@newsspool4.vodafone-ip.de>
Hi,
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);
print unpack('C', $Count), "\n"; # 2 - OK, system and console
print unpack 'H*', $SessionInfo; # not realy struct _WTS_SESSION_INFO??
THX,
Peter
------------------------------
Date: Thu, 06 Sep 2012 22:08:32 +0100
From: Rainer Weikusat <rweikusat@mssgmbh.com>
Subject: Re: Win32::API use Pointer to struct
Message-Id: <87d31y506n.fsf@sapphire.mobileactivedefense.com>
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.
------------------------------
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 3772
***************************************