in reply to Re: Problems Opening file with Perl where path has UTF8 (sorry)
in thread Problems Opening file with Perl where path has UTF8

Um, actually, Win32API::File does have CreateFileW(), just not mentioned in the documentation.

my $wPath= pack "S*", unpack( "C*", "C:/server/htdocs/DEVELOPMENT/testing/" ), 19968, 26869, 39640, 26641, unpack( "C*", "/test/test.ssi" ), 0; my $hFile= CreateFileW( $wPath, GENERIC_READ()|GENERIC_WRITE(), FILE_SHARE_READ()|FILE_SHARE_WRITE(), [], OPEN_EXISTING(), 0, [] ) or die "Can't open: $^E\n"; OsFHandleOpen( *DATFILE, $hFile, "rw" ) or die "Can't create Perl handle: $!\n"; my $strHeaderLine = <DATFILE>; print $strHeaderLine; close DATFILE;

Note, this code is untested because I composed it under Linux.

Update: I need to update createFile() to detect UTF-8 path names and do all this for you...

- tye        

Replies are listed 'Best First'.
Re^3: Problems Opening file with Perl where path has UTF8 (d'oh!)
by ikegami (Patriarch) on Nov 23, 2006 at 19:45 UTC

    Update: The striken text is only true for the system call CreateFileW, but not for Win32API::File's verion of CreateFileW.

    CreateFileW returns INVALID_FILE_HANDLE (-1) on error, not false.

    use constant INVALID_FILE_HANDLE => -1; my $hFile= CreateFileW( $wPath, GENERIC_READ()|GENERIC_WRITE(), FILE_SHARE_READ()|FILE_SHARE_WRITE(), [], OPEN_EXISTING(), 0, [] ); INVALID_FILE_HANDLE != $hFile or die "Can't open: $^E\n";

      Did you try this? Because the XS code and the documentation for Win32API::File's CreateFile() shows that a false value is returned on error.

      - tye        

        My apologies. My testing had been done with the Kernel32's CreateFileW, not with Win32API::File::CreateFileW.