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 => 0x00000001;
use constant FILE_ATTRIBUTE_HIDDEN => 0x00000002;
use constant FILE_ATTRIBUTE_SYSTEM => 0x00000004;
use constant FILE_ATTRIBUTE_DIRECTORY => 0x00000010;
use constant FILE_ATTRIBUTE_ARCHIVE => 0x00000020;
use constant FILE_ATTRIBUTE_NORMAL => 0x00000080;
use constant FILE_ATTRIBUTE_TEMPORARY => 0x00000100;
use constant FILE_ATTRIBUTE_COMPRESSED => 0x00000800;
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 Luebkert    Mailto:[EMAIL PROTECTED]
 (_/   /  )    // //       DBE Collectibles    Mailto:[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

Reply via email to