ASPN ActiveState Programmer Network
ActiveState
/ Home / Perl / PHP / Python / Tcl / XSLT /
/ Safari / My ASPN /
Cookbooks | Documentation | Mailing Lists | Modules | News Feeds | Products | User Groups


Recent Messages
List Archives
About the List
List Leaders
Subscription Options

View Subscriptions
Help

View by Topic
ActiveState
.NET Framework
Open Source
Perl
PHP
Python
Tcl
Web Services
XML & XSLT

View by Category
Database
General
SOAP
System Administration
Tools
User Interfaces
Web Programming
XML Programming


MyASPN >> Mail Archive >> perl-win32-users
perl-win32-users
RE: How to passing a hex number in Win32::API call
by Brian Raven other posts by this author
Oct 27 2009 3:17AM messages near this date
view in the new Beta List Site
RE: how to use a pointer returned by a Win32::API call | Re: ActiveState announces ActivePerl 5.10.1 build 1006
Su, Yu (Eugene) <>  wrote:
>  Hi,
>  
>  I have a DLL from FTDI (ftd2xx.dll www.ftdichip.com) for a USB
>  device. I try to write a simple perl script to list a number of (FTD)
>  USB devices connected to a PC. My code below got an error on invalid
>  parameter;   
>  
>  Argument "M-\0\0\0\0\" isn't numeric in subroutine entry at demo.pl
>  line # 
>  
>  I guess I did not pass a hex data in the function call properly. Can
>  someone help me? 
>  
>  Thanks.
>  
>  Eugene
>  
>  ######## code snippet #######
>  
>  use strict;
>  use Win32::API;
>  use Carp;
>  use warnings;
>  
>  # from FTD2xx programmer guide:
>  # FT_ListDevices(PVOID numDevs,PVOID NULL,DWORD FT_LIST_NUMBER_ONLY)
>     # FT_LIST_NUMBER_ONLY is defined in FTD2xx.h as #define
>  FT_LIST_NUMBER_ONLY = 0x80000000 # my $function = new
>  Win32::API("ftd2xx", "FT_ListDevices", "PPN", "N"); if (not defined
>  $function) { die "Can't import API FT_ListDevices: $!\n"; } my
>  $DevBuffer = " " x 80; my $FT_LIST_NUMBER_ONLY=pack('N', 0x80000000);
>  my $status=$function->Call($DevBuffer,0,$FT_LIST_NUMBER_ONLY);     
>  print "status: $status\n";
>  print "DeviceNumber: $DevBuffer";

I think that you problem is the 'pack'. Why do you think you need it?.
Just use 0x80000000 in your function call, or if you want to define it
as a constant, 'use constant FT_LIST_NUMBER_ONLY =>  0x80000000;' is more
nearly equivalent to the #define you quote, and will add to your codes
readability. For example, you dould write it something like this:

use strict;
use warnings;
use Win32::API;

use constant FT_LIST_NUMBER_ONLY =>  0x80000000;

my $function = new Win32::API("ftd2xx", "FT_ListDevices", "PPN", "N");
die "Can't import API FT_ListDevices: $!\n" unless defined $function;
my $DevBuffer = " " x 80;
my $status=$function-> Call($DevBuffer, 0 ,FT_LIST_NUMBER_ONLY);
print "status: $status\n";
print "DeviceNumber: $DevBuffer";

HTH

-- 
Brian Raven 
This e-mail may contain confidential and/or privileged information. If you are not the inten
ded 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 stric
tly forbidden.

_______________________________________________
Perl-Win32-Users mailing list
Perl-Win32-Users@[...].com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
Thread:
Jan Dubois
Yu Su
Yu Su
Brian Raven
Sisyphus
Jan Dubois

Privacy Policy | Email Opt-out | Feedback | Syndication
© ActiveState Software Inc. All rights reserved