in reply to How to create a File Handle Struct with Win32::API::Struct

File handles are created with CreateFile. Mind you, Win32API::File's GetOsFHandle will return the system handle for a given Perl file handle.

Replies are listed 'Best First'.
Re^2: How to create a File Handle Struct with Win32::API::Struct
by way (Sexton) on Dec 24, 2009 at 15:41 UTC

    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.

        Yes, i know, this's outside of my territory

        Leave me explain a bit more

        I need open a file through the dll, so i do:

        use Win32::API; use Win32::API::Struct; Win32::API::Struct->typedef( 'MYHANDLE', qw( LPCTSTR lpFileName; DWORD dwDesiredAccess; DWORD dwShareMode; LPSECURITY_ATTRIBUTES lpSecurityAttributes; DWORD dwCreationDisposition; DWORD dwFlagsAndAttributes; HANDLE hTemplateFile; )); my $handle = Win32::API::Struct->new( 'MYHANDLE' ); my $filename = './catalog.db'; my $dll = Win32::API->new( 'db.dll', 'OpenBlockFile','PS' ) or die $!; $dll->Call($filename, $handle) or die $!;

        But in this's case the dll fill the struct with the associate resource or making this, the struct never would be a handle?