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

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

Replies are listed 'Best First'.
Re^3: How to create a File Handle Struct with Win32::API::Struct
by ikegami (Patriarch) on Dec 24, 2009 at 16:02 UTC

    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?

        Are you getting a HANDLE or a struct? You keep saying handle, but you keep using a struct.

        What's the signature of the DLL function? Is it

        void __stdcall OpenBlockFile( const char* szFileName, /* Input */ HANDLE* pHandle /* Output */ )
        If so, you need something like
        my $dll = Win32::API->new( 'db.dll', 'OpenBlockFile', 'PP', 'V' ) or die $^E; my $packed_handle = pack('L', 0); $dll->Call($filename, $packed_handle); $handle = unpack('L', $packed_handle);