That won't work. The result is a trap (protection violation), because Win32::API doesn't know how to translate undef into a C-type null. This is 5.8.8, but you get the same result from 5.8.6:

C:\test>\AS817\perl\bin\perl5.8.8.exe -Mlib=\perl\site\lib -MWin32::A +PI -mstrict -w Win32::API->Import( 'urlmon', 'URLDownloadToFile', 'PPPNP', 'N', ); my $pCaller = 0; my $szURL = 'http://somedomain.com/pic.jpg'; my $szFileName = 'c:\1img.jpg'; my $dwReserved = 8; # Download from offline cache my $lpfnCB = 0; my $res = URLDownloadToFile( undef, $szURL, $szFileName, $dwReserved, undef, ) or die Win32::FormatMessage(Win32::GetLastError); ^Z Use of uninitialized value in subroutine entry at (eval 2) line 2, <DA +TA> line 164. Use of uninitialized value in subroutine entry at (eval 2) line 2, <DA +TA> line 164.

This way doesn't result in a trap, though I've failed to make it download any file. Possibly because 0x8 means fetch it from the cache, but as I don't use IE, it won't find it there.

C:\test>perl -Mlib=\perl\site\lib -MWin32::API -mstrict -w Win32::API->Import( 'urlmon', 'URLDownloadToFile', 'PPPNP', 'N', ); printf "%08x\n", URLDownloadToFile( 0, 'http://images.google.com/intl/en/images/images_res.gif', 'google.gif', 8, 0, ) or die $^E; ^Z 800c0005

The return code 0x800c005 apparently means file or server not found.

The following codes are other common error codes: - 80100003. During install, one or more files are missing from downlo +ad folder. - 800bxxxx. Anything starting with 800b is a trust failure (for examp +le, 800b010b - trust check failed). - 800Cxxxx. Anything starting with 800C is a Urlmon failure (for exam +ple, 800C0005 - file or server not found, 800C000B - connection timeout). - 80040004. User canceled.

Which doesn't make a great deal of sense as my browser can fetch the gif above, but at least the call has successfully been made without trapping.


Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
Lingua non convalesco, consenesco et abolesco. -- Rule 1 has a caveat! -- Who broke the cabal?
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.

In reply to Re^2: Win32::API help by BrowserUk
in thread Win32::API help by Zukoff

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.