RE: Invalid type 'Q' in pack

2011-02-15 Thread Brian Raven
-Original Message-
From: perl-win32-users-boun...@listserv.activestate.com
[mailto:perl-win32-users-boun...@listserv.activestate.com] On Behalf Of
Mark Dootson
Sent: 15 February 2011 03:39
To: Michael Cohen
Cc: perl-win32-users@listserv.ActiveState.com
Subject: Re: Invalid type 'Q' in pack

> Hi,
>
> There is no Q template for 32bit Perl as you have noticed.
>
> One solution may be 
>
> define your struct as two DWORDS for each DWORD64, then split and join

> as necessary in your Perl code.
>
> 'pack' and 'unpack' are your friends in splitting / joining your
DWORD64 
> / DWORDs
>
> If you could get at the pack / unpack inside Win32::API::Struct 
> directly, then 'a8' would work as a replacement for 'Q' I think.
Spoken 
> without testing of course.
>
> regards
>
> Mark
>
>
>
> On 15/02/2011 02:54, Michael Cohen wrote:
> > I am trying to replace an old and unsupported Win32 library. In
doing
> > so, I am attempting to get the following piece of code to work prior
to
> > adding it to my own library:
> >
> >  Cut Here -
> > #!/usr/bin/perl -w
> > use strict;
> >
> > use Win32;
> > use Win32::API;
> >
> > Win32::API::Struct->typedef('MEMORYSTATUSEX', qw(
> > DWORD dwLength;
> > DWORD dwMemoryLoad;
> > DWORD64 ullTotalPhys;
> > DWORD64 ullAvailPhys;
> > DWORD64 ullTotalPageFile;
> > DWORD64 ullAvailPageFile;
> > DWORD64 ullTotalVirtual;
> > DWORD64 ullAvailVirtual;
> > DWORD64 ullAvailExtendedVirtual;
> > ));
> >
> > Win32::API->Import('kernel32',
> > 'BOOL GlobalMemoryStatusEx(LPMEMORYSTATUSEX lpBuffer)');
> >
> > # my $memoryInfo = Win32::API::Struct->new('MEMORYSTATUSEX');
> > tie my %memoryInfo, 'Win32::API::Struct', 'MEMORYSTATUSEX';
> >
> > my $rc = GlobalMemoryStatusEx(\%memoryInfo);
> >
> > printf ("TotalPhys = %d\n", $memoryInfo{ullTotalPhys});
> >
> > print ("Finished\n");
> >
> >  Cut Here -
> >
> > When I try to run this program on a x86 version of ActivePerl 5.8.9
> > Build 828, I get the error:
> > Invalid type 'Q' in pack at C:/Perl/lib/Win32/API/Struct.pm line
230.
> > when it gets to line 25 (actual call of the Win32 API).
> >
> > Since I need to run this bit of code on both the 32-bit and 64-bit
> > Windows, how can I get this to work?
> >
> > API Info: http://msdn.microsoft.com/en-us/library/aa366589

I would say that it is primarily an issue with Win32::API::Type which
seems to specify Q/q as the template character for a number of types
that are (I think) valid for 32 bit windows. It should perhaps either
provide a suitable diagnostic if support for 64 bit integer values is
not available, or perform the necessary conversion. You might want to
take that up with the module's maintainer.

I don't know if it is possible/practical to build a 32 bit version of
Perl with support for 64 bit integers. That would either be a question
for Activestate, or you if you want to try building Perl yourself.

I agree with the Mark's suggested work around of using 2 DWORDs instead
of DWORD64, with some extra work at your end to combine them. I leave
determining the word order as an exercise for the reader, but you may
also want to consider using Math::BigInt to store the combined values,
just to be on the safe side.

HTH


-- 
Brian Raven 
 
Please consider the environment before printing this e-mail.

This e-mail may contain confidential and/or privileged information. If you are 
not the intended recipient or have received this e-mail in error, please advise 
the sender immediately by reply e-mail and delete this message and any 
attachments without retaining a copy.

Any unauthorised copying, disclosure or distribution of the material in this 
e-mail is strictly forbidden.
___
Perl-Win32-Users mailing list
Perl-Win32-Users@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs


Re: Invalid type 'Q' in pack

2011-02-14 Thread Mark Dootson
Hi,

There is no Q template for 32bit Perl as you have noticed.

One solution may be 

define your struct as two DWORDS for each DWORD64, then split and join 
as necessary in your Perl code.

'pack' and 'unpack' are your friends in splitting / joining your DWORD64 
/ DWORDs

If you could get at the pack / unpack inside Win32::API::Struct 
directly, then 'a8' would work as a replacement for 'Q' I think. Spoken 
without testing of course.

regards

Mark



On 15/02/2011 02:54, Michael Cohen wrote:
> I am trying to replace an old and unsupported Win32 library. In doing
> so, I am attempting to get the following piece of code to work prior to
> adding it to my own library:
>
>  Cut Here -
> #!/usr/bin/perl -w
> use strict;
>
> use Win32;
> use Win32::API;
>
> Win32::API::Struct->typedef('MEMORYSTATUSEX', qw(
> DWORD dwLength;
> DWORD dwMemoryLoad;
> DWORD64 ullTotalPhys;
> DWORD64 ullAvailPhys;
> DWORD64 ullTotalPageFile;
> DWORD64 ullAvailPageFile;
> DWORD64 ullTotalVirtual;
> DWORD64 ullAvailVirtual;
> DWORD64 ullAvailExtendedVirtual;
> ));
>
> Win32::API->Import('kernel32',
> 'BOOL GlobalMemoryStatusEx(LPMEMORYSTATUSEX lpBuffer)');
>
> # my $memoryInfo = Win32::API::Struct->new('MEMORYSTATUSEX');
> tie my %memoryInfo, 'Win32::API::Struct', 'MEMORYSTATUSEX';
>
> my $rc = GlobalMemoryStatusEx(\%memoryInfo);
>
> printf ("TotalPhys = %d\n", $memoryInfo{ullTotalPhys});
>
> print ("Finished\n");
>
>  Cut Here -
>
> When I try to run this program on a x86 version of ActivePerl 5.8.9
> Build 828, I get the error:
> Invalid type 'Q' in pack at C:/Perl/lib/Win32/API/Struct.pm line 230.
> when it gets to line 25 (actual call of the Win32 API).
>
> Since I need to run this bit of code on both the 32-bit and 64-bit
> Windows, how can I get this to work?
>
> API Info: http://msdn.microsoft.com/en-us/library/aa366589
>
> Regards,
> Michael Cohen
>
>
>
> ___
> Perl-Win32-Users mailing list
> Perl-Win32-Users@listserv.ActiveState.com
> To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

___
Perl-Win32-Users mailing list
Perl-Win32-Users@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs


Invalid type 'Q' in pack

2011-02-14 Thread Michael Cohen
I am trying to replace an old and unsupported Win32 library.  In doing so, 
I am attempting to get the following piece of code to work prior to adding 
it to my own library:

 Cut Here -
#!/usr/bin/perl -w
use strict;

use Win32;
use Win32::API;

Win32::API::Struct->typedef('MEMORYSTATUSEX', qw(
  DWORD dwLength;
  DWORD dwMemoryLoad;
  DWORD64   ullTotalPhys;
  DWORD64   ullAvailPhys;
  DWORD64   ullTotalPageFile;
  DWORD64   ullAvailPageFile;
  DWORD64   ullTotalVirtual;
  DWORD64   ullAvailVirtual;
  DWORD64   ullAvailExtendedVirtual;
));

Win32::API->Import('kernel32',
  'BOOL GlobalMemoryStatusEx(LPMEMORYSTATUSEX lpBuffer)');

# my $memoryInfo = Win32::API::Struct->new('MEMORYSTATUSEX');
tie my %memoryInfo, 'Win32::API::Struct', 'MEMORYSTATUSEX';

my $rc = GlobalMemoryStatusEx(\%memoryInfo);

printf ("TotalPhys = %d\n", $memoryInfo{ullTotalPhys});

print ("Finished\n");

 Cut Here -

When I try to run this program on a x86 version of ActivePerl 5.8.9 Build 
828, I get the error:
  Invalid type 'Q' in pack at C:/Perl/lib/Win32/API/Struct.pm line 230.
when it gets to line 25 (actual call of the Win32 API).

Since I need to run this bit of code on both the 32-bit and 64-bit 
Windows, how can I get this to work?

API Info:  http://msdn.microsoft.com/en-us/library/aa366589

Regards,
Michael Cohen
___
Perl-Win32-Users mailing list
Perl-Win32-Users@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs