3

Do you need to close the handles from WinHttpOpen(), WinHttpConnect() and WinHttpOpenRequest(), after you use them with async mode WinHttpOpen().

I suppose they need to be, but how is that done because everything is asynchronously done, I've seen that the last called event from the callback was WINHTTP_CALLBACK_STATUS_DATA_AVAILABLE, but im not sure if this is always the case (called last).

So do I need to close the handles, and if yes how?

2198du19as
  • 33
  • 3
  • Is [the information in the documentation](https://learn.microsoft.com/en-gb/windows/win32/api/winhttp/nf-winhttp-winhttpclosehandle) not sufficient? – Asteroids With Wings May 13 '20 at 12:41

1 Answers1

0

Yes, WinHTTP handles need to be closed. WinHttOpen() documentation:

After the calling application has finished using the HINTERNET handle returned by WinHttpOpen, it must be closed using the WinHttpCloseHandle function.

For asynchronous mode this can be done on the class destructor. In this case the handle can be a member variable so it's not lost. If you are using the main function, simply close the handle at the end.

Cosmin
  • 21,216
  • 5
  • 45
  • 60
  • Actually I figured it out after i posted the question :D. I did it when i get the final data response from the callback i set a flag and that flag is checked, then returns the function which had WinHttpOpen() and there it closes the handles – 2198du19as May 13 '20 at 14:23