Closes a WinINet Internet handle opened by InternetOpen, InternetConnect, InternetOpenUrl, or similar functions.
BOOL InternetCloseHandle(
HINTERNET hInternet
);
| Parameter | Type | Description |
|---|---|---|
hInternet |
HINTERNET |
Handle to an Internet session, request, or FTP file. |
Returns TRUE if the function succeeds; otherwise returns FALSE. Use GetLastError for extended error information.
InternetCloseHandle must not be used after the call.InternetCloseHandle on an already closed handle results in undefined behavior.#include <windows.h>
#include <wininet.h>
#pragma comment(lib, "wininet.lib")
int main() {
HINTERNET hSession = InternetOpenA("MyApp", INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0);
if (!hSession) {
printf("InternetOpen failed. Error: %lu\\n", GetLastError());
return 1;
}
HINTERNET hConnect = InternetConnectA(hSession, "example.com",
INTERNET_DEFAULT_HTTP_PORT,
NULL, NULL, INTERNET_SERVICE_HTTP, 0, 0);
if (!hConnect) {
printf("InternetConnect failed. Error: %lu\\n", GetLastError());
InternetCloseHandle(hSession);
return 1;
}
// ... perform request ...
// Close the child handle first
InternetCloseHandle(hConnect);
// Then close the session handle
InternetCloseHandle(hSession);
return 0;
}