in reply to Use Windows wimgapi dll

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.)

Replies are listed 'Best First'.
Re^2: Use Windows wimgapi dll
by iea (Beadle) on Aug 04, 2008 at 06:52 UTC
    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

        One thing I forgot is that you need to add "\0" your string pre-encoding (or "\0" to your post-encoding). Win32::API will add the byte \0 for you, but the char \0 is expected (which is encoded as two \0 bytes).

        So what's the error message? I bet it can be fetched via GetLastError (and a quick look at the docs would confirm that).