in reply to opening filehandle with Win32API::File seems to return scalar

Pass the Win32 native handle to OsFHandleOpen() to get a Perl file handle.

- tye        

  • Comment on Re: opening filehandle with Win32API::File seems to return scalar (OsFHandleOpen)

Replies are listed 'Best First'.
Re^2: opening filehandle with Win32API::File seems to return scalar (OsFHandleOpen)
by Lotus1 (Vicar) on Oct 14, 2014 at 21:39 UTC

    I got it to work that way but only with a baretext filehandle and without using strict. When I used a lexical variable I got the error message "Can't use an undefined value as a symbol reference at D:\Users\lock\t2.pl line 18." Line 18 is the print statement.

    I still don't understand why the tie didn't work. There was no implementation of TIESCALAR in the module but I found TIEHANDLE.

    #use strict; use warnings; use Data::Dumper; use Win32API::File 0.08 qw( :ALL ); my $testfile = "test.xml"; print "file exists\n" if -e $testfile; my $hObject = createFile( $testfile, 'rw k e' ); unless ( $hObject ) { die "error creating handle: $^E\n"; } print Dumper( $hObject); my $fh; OsFHandleOpen( FHTEST, $hObject, 'rw' ) or die "OsFHandleOpen: $^E\n"; print FHTEST "test"; print "finished\n"; __DATA__ output: Name "main::FHTEST" used only once: possible typo at D:\Users\lock\t2. +pl line 18. file exists $VAR1 = 116; finished
      OsFHandleOpen( my $fh = IO::Handle->new(), $hObject, 'rw' ) or die ...

      It would actually have a saner interface if it weren't emulating open's weird interface. And it has yet to adopt the new idea of open autovivifying when passed undef instead of a handle (though I recall coding that improvement long ago, just never got released, it seems).

      - tye