You are using asynchronous mode (
INTERNET_FLAG_ASYNC
). In this case, all functions will return immediately without waiting for the requested action to be finished. The error 997 /
ERROR_IO_PENDING
indicates that such an action has not been finished yet.
With asynchronous operations, use the
InternetSetStatusCallback[
^] function to be notified when operations has been finished. See also the
Asynchronous Example Application[
^] in the MSDN.