InternetSetStatusCallback function
Namespace: WinInet
Header: wininet.h
Library: Wininet.lib
Syntax
DWORD WINAPI InternetSetStatusCallback(
HINTERNET hInternet,
INTERNET_STATUS_CALLBACK lpfnInternetCallback
);
Parameters
| hInternet | Handle to an Internet object. This can be a session, connection, request, or FTP file handle. |
|---|---|
| lpfnInternetCallback | Pointer to the callback function that receives status notifications. Use NULL to remove the callback. |
Return value
Returns the previous callback function pointer. If the function fails, the return value is NULL. Call GetLastError for extended error information.
Remarks
- The callback receives a
DWORDstatus code and aLPVOIDoptional data pointer. Refer to InternetStatusCallback for details. - Only one callback can be set per handle at a time. Setting a new callback replaces the previous one.
- When the callback is no longer needed, set it to
NULLto avoid memory leaks. - Be aware of threading issues; the callback may be called on a worker thread belonging to WinInet.
Requirements
- Minimum supported client: Windows 2000
- Header:
wininet.h - Library:
Wininet.lib
Examples
The following example sets a status callback for an HTTP request and prints status messages to the console.
#include <windows.h>
#include <wininet.h>
#include <stdio.h>
void CALLBACK StatusCallback(HINTERNET hInternet, DWORD_PTR dwContext, DWORD dwInternetStatus,
LPVOID lpvStatusInformation, DWORD dwStatusInformationLength)
{
switch (dwInternetStatus) {
case INTERNET_STATUS_RESOLVING_NAME:
printf("Resolving host name...\n");
break;
case INTERNET_STATUS_CONNECTING_TO_SERVER:
printf("Connecting to server...\n");
break;
case INTERNET_STATUS_SENDING_REQUEST:
printf("Sending request...\n");
break;
case INTERNET_STATUS_RECEIVING_RESPONSE:
printf("Receiving response...\n");
break;
default:
break;
}
}
int main(void)
{
HINTERNET hSession = InternetOpenA("MyAgent", INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0);
if (!hSession) return 1;
InternetSetStatusCallback(hSession, StatusCallback);
HINTERNET hConnect = InternetConnectA(hSession, "www.example.com", INTERNET_DEFAULT_HTTP_PORT,
NULL, NULL, INTERNET_SERVICE_HTTP, 0, 0);
if (!hConnect) return 1;
HINTERNET hRequest = HttpOpenRequestA(hConnect, "GET", "/", NULL, NULL, NULL,
INTERNET_FLAG_RELOAD, 0);
if (!hRequest) return 1;
HttpSendRequestA(hRequest, NULL, 0, NULL, 0);
InternetCloseHandle(hRequest);
InternetCloseHandle(hConnect);
InternetCloseHandle(hSession);
return 0;
}