way has asked for the wisdom of the Perl Monks concerning the following question:

Hello Fellows!

I've a dll without the documentation, one of the parameters to call of the needed function is a file handle. How could i create it with Win32::API::Struct?

If i use a filehandle of Perl it complain as "Can't call method "Pack" on an undefined value"

Thank and Merry Christmas!

  • Comment on How to create a File Handle Struct with Win32::API::Struct

Replies are listed 'Best First'.
Re: How to create a File Handle Struct with Win32::API::Struct
by ikegami (Patriarch) on Dec 24, 2009 at 07:15 UTC
    File handles are created with CreateFile. Mind you, Win32API::File's GetOsFHandle will return the system handle for a given Perl file handle.

      If i use Win32::File to create a file handle, Perl complain about can't packetize

      So i created a struct like the example becouse the dll was made with visual c++ and appear work

      Win32::API::Struct->typedef( 'HANDLE', qw( LPCTSTR lpFileName; DWORD dwDesiredAccess; DWORD dwShareMode; LPSECURITY_ATTRIBUTES lpSecurityAttributes; DWORD dwCreationDisposition; DWORD dwFlagsAndAttributes; HANDLE hTemplateFile; )); my $handle = Win32::API::Struct->new( 'HANDLE' );

      Unfortunately without documentation, i receive a Dll Runtime Error, so i guest that i missed other parameter but this's another history

      Thank and Merry Christmas

        You seem to be completely misunderstanding the nature of a handle. A handle is an opaque identifier (32-bit number) given to you by the system in response to a request that allocates a system resource. You can't just make one up, because the associated resource would be missing.

Re: How to create a File Handle Struct with Win32::API::Struct
by Anonymous Monk on Dec 24, 2009 at 07:06 UTC
      Backwards. GetOsFHandle returns the file handle. fileno is returns a C lib emulation of unix file descriptors.

      I'm trying of load and use a dll on Perl, the function itself needed a struct of file handle because read a file and pass it to it, that was a good point to start.

      Thank