Compartilhar via


About HINTERNET Handles

A version of this page is also available for

Windows Embedded CE 6.0 R3

4/8/2010

Handles created and used by the Windows Internet Services (WinInet) functions are called HINTERNETs. These HINTERNET handles are not native system handles. They are only returned by the WinInet functions. As such, you cannot use HINTERNET handles with functions such as ReadFile or CloseHandle, nor can you use native system handles, returned by functions such as CreateFile, with the WinInet functions.

HINTERNET handles are maintained in a tree hierarchy in which a higher-level function must be called before a dependent function is called. The handle returned by the InternetOpen function is the root node. Handles returned by the InternetConnect function occupy the next level. Handles returned by the FtpOpenFile, FtpFindFirstFile, and HttpOpenRequest functions are the leaf nodes.

The following illustration shows the hierarchy of the HINTERNET handles. Each box represents a WinInet function that returns an HINTERNET handle.

Aa919689.51eff039-9c2b-4e59-815b-658f01c748d2(en-us,MSDN.10).gif

At the top level is InternetOpen, which creates the root HINTERNET. The next level contains InternetOpenUrl and InternetConnect. The functions that use the HINTERNET handle returned by InternetConnect make up the last level.

All HINTERNET handles can be closed by InternetCloseHandle. Client applications must close all HINTERNET handles derived from the HINTERNET handle to be closed before calling InternetCloseHandle.

The following code example shows the handle hierarchy for the WinInet functions.

HINTERNET hRootHandle, hOpenUrlHandle;
hRootHandle = InternetOpen(
                           TEXT("Example"), 
                           INTERNET_OPEN_TYPE_DIRECT, 
                           NULL, 
                           NULL, 
                           0);
hOpenUrlHandle = InternetOpenUrl(
                              hRootHandle, 
                              TEXT("https://www.server.com/default.htm"),
                              NULL,
                              0,
                              INTERNET_FLAG_RAW_DATA,
                              0);

// Close the handle created by InternetOpenUrl, so that the
// InternetOpen handle can be closed.
InternetCloseHandle(hOpenUrlHandle); 

// Close the handle created by InternetOpen.
InternetCloseHandle(hRootHandle);

Note

Handle values are recycled quickly. Therefore, if a handle is closed and a new handle is generated immediately, the new handle can have the same value as the handle just closed.

See Also

Other Resources

WinInet Application Development