in reply to Win32::API help

One final thing to notice (since the immediate problem (crash) seems to be resolved with the above suggestions):

Your error checking logic has to be inverted. Otherwise you end up dying with "Command completed successfully" after a successful download. ;-)