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

Hi, i am trying to use the wingapi.dll with perl - here the dll function for C
HANDLE WINAPI WIMCreateFile( LPWSTR lpszWimPath, DWORD dwDesiredAccess, DWORD dwCreationDisposition, DWORD dwFlagsAndAttributes, DWORD dwCompressionType, LPDWORD lpdwCreationResult );
Here my code ...
use Win32::API; use Data::Dumper; use FileHandle; #Open Filehandler $fh = new FileHandle; if ($fh->open("< C:\\data.wim")) { $fh->close; } my $wimfile = new Win32::API("wimgapi", "WIMCreateFile", ['P','C','C', +'C','C','C'], 'N'); my $value = $wimfile->Call($fh,WIM_GENERIC_WRITE,WIM_OPEN_EXISTING,WIM +_FLAG_VERIFY,WIM_COMPRESS_NONE,WIM_OPENED_EXISTING); print $value; #Returns: # 0 print Dumper($wimfile); #Returns: # $VAR1 = bless( { # 'out' => 1, # 'dll' => 1940783104, # 'procname' => 'WIMCreateFile', # 'proc' => 1940839096, # 'dllname' => 'wimgapi', # 'in' => [ # 2, # 6, # 6, # 6, # 6, # 6 # ] # }, 'Win32::API' ); # I: value is an integer (int) # N: value is a number (long) # F: value is a floating point number (float) # D: value is a double precision number (double) # C: value is a char (char) # P: value is a pointer (to a string, structure, etc...) # S: value is a Win32::API::Struct object (see below) # K: value is a Win32::API::Callback object (see Win32::API::Callback)
I dont know if its even possible to call function from the wimgapi. Thanks

Replies are listed 'Best First'.
Re: Use Windows wimgapi dll
by Anonymous Monk on Jul 31, 2008 at 06:05 UTC
    Where does WIM_GENERIC_WRITE.. come from?
    use strict; use warnings;
Re: Use Windows wimgapi dll
by Anonymous Monk on Jul 31, 2008 at 06:12 UTC
    If you add
    print $fh;
    You'll get something resembling FileHandle=GLOB(0x1990c80) not C:\data.wim as you probably wanted.
Re: Use Windows wimgapi dll
by ikegami (Patriarch) on Jul 31, 2008 at 07:03 UTC

    The first argument is a wide character string (LPWSTR), but you pass a Perl glob object. I imagine you'd need to pass the result of the following:

    use Encode qw( encode ); encode('UCS-2le', 'C:\\data.wim')

    Why do you open a file only to immediately close the handle?

    I also wonder why you FileHandle is used over the simpler and safer open.

    use FileHandle qw( ); my $fh = new FileHandle; $fh->open("< C:\\data.wim") or die;

    vs

    open(my $fh, "<", "C:\\data.wim") or die;

    (Add use IO::Handle; if you want to use $fh like an object.)

      Hi, thanks for your fast replies and sry for my delay.
      >>Where does WIM_GENERIC_WRITE.. come from?
      They are defined in the wimgapi doc, you can find them with waik.

      @ikegami I did try a simple open ... I added your encode line but it still doesnt work.
      use Encode qw( encode ); my $filehandler = encode('UCS-2le', 'C:\\data.wim'); my $wimfile = new Win32::API("wimgapi", "WIMCreateFile", ['S','C','C', +'C','C','C'], 'N'); my $value = $wimfile->Call($filehandler,WIM_GENERIC_WRITE,WIM_OPEN_EXI +STING,WIM_FLAG_VERIFY,WIM_COMPRESS_NONE,WIM_OPENED_EXISTING);
      i get following errorcode...
      semi-panic: attempt to dup freed string at test.pl line 10, <DATA> lin +e 164. Can't call method "Pack" on an undefined value at test.pl line 10, <DA +TA> line 164.
      anybody knows what i´m doing wrong?
      thanks for your help
        thanks for your answer ... I added "\0" to the string but there is no change. I dont get any error message it just returns 0 as filehandle. my $hWim = $wimfile->Call(... #returns 0 see code above