Re: More Win32::API Help....

2004-11-17 Thread $Bill Luebkert
Paul Sobey wrote:

> You're a genius - thankyou.
> 
> I wonder why the prototype method doesn't work? Seems a bit frustrating!

That whole set of modules is a bit flakey for my taste.  I made lots
of quick changes to keep warnings from popping up and had lots of
trouble with structs and such.  You have to try alternate methods
for everything until you find something that works.  :)

-- 
  ,-/-  __  _  _ $Bill LuebkertMailto:[EMAIL PROTECTED]
 (_/   /  )// //   DBE CollectiblesMailto:[EMAIL PROTECTED]
  / ) /--<  o // //  Castle of Medieval Myth & Magic http://www.todbe.com/
-/-' /___/_<_http://dbecoll.tripod.com/ (My Perl/Lakers stuff)
___
Perl-Win32-Users mailing list
[EMAIL PROTECTED]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs


RE: More Win32::API Help....

2004-11-17 Thread Paul Sobey
You're a genius - thankyou.

I wonder why the prototype method doesn't work? Seems a bit frustrating!

P.



-Original Message-
From: $Bill Luebkert [mailto:[EMAIL PROTECTED] 
Sent: 17 November 2004 13:37
To: Paul Sobey
Cc: [EMAIL PROTECTED]
Subject: Re: More Win32::API Help

Paul Sobey wrote:

> Hi All,
>  
> Can anyone see what's wrong with the following? Doesn't seem to matter what 
> filename I pass in, I still get the same result, error 123 (The filename, 
> directory name, or volume label syntax is incorrect.). As far as I can tell 
> from the debug output, the structs are getting set up correctly. Am I passing 
> the filename in properly? Tried appending a \0 but that didn't help either :(
>  
> Function definition is here: 
> http://msdn.microsoft.com/library/default.asp?url=/library/en-us/fileio/base/findfirstfile.asp

It doesn't seem to like the impoirt method for me.  Try the code at the end
and see if it makes a difference.

> use Win32::API;
>  
> $Win32::API::DEBUG = 1;
>  
> Win32::API::Struct->typedef("FILETIME", qw(
>  DWORD dwLowDateTime;
>  DWORD dwHighDateTime;
> ));
>  
> Win32::API::Struct->typedef("WIN32_FIND_DATA", qw(
>  DWORD dwFileAttributes;
>  FILETIME ftCreationTime;
>  FILETIME ftLastAccessTime;
>  FILETIME ftLastWriteTime;
>  DWORD nFileSizeHigh;
>  DWORD nFileSizeLow;
>  DWORD dwReserved0;
>  DWORD dwReserved1;
>  TCHAR cFileName[260];
>  TCHAR cAlternateFileName[14];
> ));
>  
> 
> Win32::API->Import("kernel32", "HANDLE FindFirstFile( LPCTSTR lpFileName, 
> LPWIN32_FIND_DATA lpFindFileData )") or die;
>  
> my $FileName = "C:\\WINNT";
> my $FileInfo = Win32::API::Struct->new("WIN32_FIND_DATA");
>  
> my $handle = FindFirstFile($FileName, $FileInfo);
>  
> print "Handle returned is $handle\n";
>  
> printf("Error is %d - %s",Win32::GetLastError(), 
> Win32::FormatMessage(Win32::GetLastError()));

use strict;
use Win32::API;
use Data::Dumper; $Data::Dumper::Indent=1; $Data::Dumper::Sortkeys=1;

$Win32::API::DEBUG = 0;

Win32::API::Struct->typedef('FILETIME', qw(
  DWORD dwLowDateTime;
  DWORD dwHighDateTime;
)); # 8 bytes

use constant FILE_ATTRIBUTE_READONLY => 0x0001;
use constant FILE_ATTRIBUTE_HIDDEN => 0x0002;
use constant FILE_ATTRIBUTE_SYSTEM => 0x0004;
use constant FILE_ATTRIBUTE_DIRECTORY => 0x0010;
use constant FILE_ATTRIBUTE_ARCHIVE => 0x0020;
use constant FILE_ATTRIBUTE_NORMAL => 0x0080;
use constant FILE_ATTRIBUTE_TEMPORARY => 0x0100;
use constant FILE_ATTRIBUTE_COMPRESSED => 0x0800;
use constant MAX_PATH => 260;

Win32::API::Struct->typedef('WIN32_FIND_DATA', qw(
  DWORD dwFileAttributes;
  FILETIME ftCreationTime;
  FILETIME ftLastAccessTime;
  FILETIME ftLastWriteTime;
  DWORD nFileSizeHigh;
  DWORD nFileSizeLow;
  DWORD dwReserved0;
  DWORD dwReserved1;
  TCHAR cFileName[260];
  TCHAR cAlternateFileName[14];
)); # 4+8+8+8+4+4+4+4+260+14=318 bytes

Win32::API->Import('kernel32', 'HANDLE FindFirstFile (LPCTSTR lpFileName, ' .
  'LPWIN32_FIND_DATA lpFindFileData)') or die "Import FindFirstFile: $!($^E)";

# added the old non-import call

my $FindFirstFile = new Win32::API('kernel32', 'FindFirstFile', 'PS', 'N') or
  die "Find FindFirstFile: $^E";

my $FileName = 'C:\\WINNT';
# my $FileName = "D:\\Windows"; # for my test on XP
my $FileInfo = Win32::API::Struct->new('WIN32_FIND_DATA');
print Data::Dumper->Dump([$FileName, $FileInfo], [qw($FileName $FileInfo)]);

# changed to ->Call format

# my $handle = FindFirstFile ($FileName, $FileInfo);
my $handle = $FindFirstFile->Call($FileName, $FileInfo);
print "Handle returned is $handle\n";
if ($handle < 0) {
printf "Error is %d - %s\n", Win32::GetLastError (),
  Win32::FormatMessage (Win32::GetLastError ());
} else {
print Data::Dumper->Dump([$FileInfo], [qw($FileInfo)]);
}

__END__



-- 
  ,-/-  __  _  _ $Bill LuebkertMailto:[EMAIL PROTECTED]
 (_/   /  )// //   DBE CollectiblesMailto:[EMAIL PROTECTED]
  / ) /--<  o // //  Castle of Medieval Myth & Magic http://www.todbe.com/
-/-' /___/_<_http://dbecoll.tripod.com/ (My Perl/Lakers stuff)



*
Gloucester Research Limited believes the information 
provided herein is reliable. While every care has been 
taken to ensure accuracy, the information is furnished 
to the recipients with no warranty as to the completeness 
and accuracy of its contents and on condition that any 
errors or omissions shall not be made the basis for any 
claim, demand or cause for action.
*


___
Perl-Win32-Users mailing list
[EMAIL PROTECTED]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs


Re: More Win32::API Help....

2004-11-17 Thread $Bill Luebkert
Paul Sobey wrote:

> Hi All,
>  
> Can anyone see what's wrong with the following? Doesn't seem to matter what 
> filename I pass in, I still get the same result, error 123 (The filename, 
> directory name, or volume label syntax is incorrect.). As far as I can tell 
> from the debug output, the structs are getting set up correctly. Am I passing 
> the filename in properly? Tried appending a \0 but that didn't help either :(
>  
> Function definition is here: 
> http://msdn.microsoft.com/library/default.asp?url=/library/en-us/fileio/base/findfirstfile.asp

It doesn't seem to like the impoirt method for me.  Try the code at the end
and see if it makes a difference.

> use Win32::API;
>  
> $Win32::API::DEBUG = 1;
>  
> Win32::API::Struct->typedef("FILETIME", qw(
>  DWORD dwLowDateTime;
>  DWORD dwHighDateTime;
> ));
>  
> Win32::API::Struct->typedef("WIN32_FIND_DATA", qw(
>  DWORD dwFileAttributes;
>  FILETIME ftCreationTime;
>  FILETIME ftLastAccessTime;
>  FILETIME ftLastWriteTime;
>  DWORD nFileSizeHigh;
>  DWORD nFileSizeLow;
>  DWORD dwReserved0;
>  DWORD dwReserved1;
>  TCHAR cFileName[260];
>  TCHAR cAlternateFileName[14];
> ));
>  
> 
> Win32::API->Import("kernel32", "HANDLE FindFirstFile( LPCTSTR lpFileName, 
> LPWIN32_FIND_DATA lpFindFileData )") or die;
>  
> my $FileName = "C:\\WINNT";
> my $FileInfo = Win32::API::Struct->new("WIN32_FIND_DATA");
>  
> my $handle = FindFirstFile($FileName, $FileInfo);
>  
> print "Handle returned is $handle\n";
>  
> printf("Error is %d - %s",Win32::GetLastError(), 
> Win32::FormatMessage(Win32::GetLastError()));

use strict;
use Win32::API;
use Data::Dumper; $Data::Dumper::Indent=1; $Data::Dumper::Sortkeys=1;

$Win32::API::DEBUG = 0;

Win32::API::Struct->typedef('FILETIME', qw(
  DWORD dwLowDateTime;
  DWORD dwHighDateTime;
)); # 8 bytes

use constant FILE_ATTRIBUTE_READONLY => 0x0001;
use constant FILE_ATTRIBUTE_HIDDEN => 0x0002;
use constant FILE_ATTRIBUTE_SYSTEM => 0x0004;
use constant FILE_ATTRIBUTE_DIRECTORY => 0x0010;
use constant FILE_ATTRIBUTE_ARCHIVE => 0x0020;
use constant FILE_ATTRIBUTE_NORMAL => 0x0080;
use constant FILE_ATTRIBUTE_TEMPORARY => 0x0100;
use constant FILE_ATTRIBUTE_COMPRESSED => 0x0800;
use constant MAX_PATH => 260;

Win32::API::Struct->typedef('WIN32_FIND_DATA', qw(
  DWORD dwFileAttributes;
  FILETIME ftCreationTime;
  FILETIME ftLastAccessTime;
  FILETIME ftLastWriteTime;
  DWORD nFileSizeHigh;
  DWORD nFileSizeLow;
  DWORD dwReserved0;
  DWORD dwReserved1;
  TCHAR cFileName[260];
  TCHAR cAlternateFileName[14];
)); # 4+8+8+8+4+4+4+4+260+14=318 bytes

Win32::API->Import('kernel32', 'HANDLE FindFirstFile (LPCTSTR lpFileName, ' .
  'LPWIN32_FIND_DATA lpFindFileData)') or die "Import FindFirstFile: $!($^E)";

# added the old non-import call

my $FindFirstFile = new Win32::API('kernel32', 'FindFirstFile', 'PS', 'N') or
  die "Find FindFirstFile: $^E";

my $FileName = 'C:\\WINNT';
# my $FileName = "D:\\Windows"; # for my test on XP
my $FileInfo = Win32::API::Struct->new('WIN32_FIND_DATA');
print Data::Dumper->Dump([$FileName, $FileInfo], [qw($FileName $FileInfo)]);

# changed to ->Call format

# my $handle = FindFirstFile ($FileName, $FileInfo);
my $handle = $FindFirstFile->Call($FileName, $FileInfo);
print "Handle returned is $handle\n";
if ($handle < 0) {
printf "Error is %d - %s\n", Win32::GetLastError (),
  Win32::FormatMessage (Win32::GetLastError ());
} else {
print Data::Dumper->Dump([$FileInfo], [qw($FileInfo)]);
}

__END__



-- 
  ,-/-  __  _  _ $Bill LuebkertMailto:[EMAIL PROTECTED]
 (_/   /  )// //   DBE CollectiblesMailto:[EMAIL PROTECTED]
  / ) /--<  o // //  Castle of Medieval Myth & Magic http://www.todbe.com/
-/-' /___/_<_http://dbecoll.tripod.com/ (My Perl/Lakers stuff)
___
Perl-Win32-Users mailing list
[EMAIL PROTECTED]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs