[32509] in Perl-Users-Digest
Perl-Users Digest, Issue: 3774 Volume: 11
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sat Sep 8 18:10:55 2012
Date: Sat, 8 Sep 2012 15:09:02 -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 Sat, 8 Sep 2012 Volume: 11 Number: 3774
Today's topics:
Re: Win32::API use Pointer to struct <ben@morrow.me.uk>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Sat, 8 Sep 2012 20:46:54 +0100
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: Win32::API use Pointer to struct
Message-Id: <eujsh9-f53.ln1@anubis.morrow.me.uk>
Quoth Peter Arnhold <Peter.Arnhold@web.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;
Bear in mind that it's not in general safe to assume structure members
will be contiguous: there may be padding. Usually on a 32bit machine,
with members which are all 32bits long, that won't happen, but under
other circumstances it might.
Working out where the padding is can be difficult. The only safe ways
are either to write a little C program which includes all the right
headers and prints out the 'offsetof' each member, or to examine the
debug symbols in a debugger (assuming you've got debug symbols; the
symbols for Windows DLLs can be downloaded from MSDN).
Alternatively, I find it's often easier to just bite the bullet and
write a proper extension (in XS). Once you've written one it's not at
all hard, at least for simple cases.
[There was once (well, there is still, but it doesn't generally work any
more) a program called 'c2ph' which came with perl, which would compile
a little C file, read the debugging information, and write a
Perl-4-style .ph file with functions for unpacking a structure. Now that
Linux distros (at least) have started installing debug symbols by
default, it might be interesting to try updating it...]
Ben
------------------------------
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 3774
***************************************