
The Wininet API is a powerful tool for developers, providing a wide range of features for building robust and efficient networking applications.
It supports both synchronous and asynchronous connections, allowing developers to choose the approach that best fits their needs.
The API also includes support for HTTP 1.1 and HTTPS protocols, enabling secure and reliable communication over the internet.
Wininet is capable of handling multiple connections simultaneously, making it suitable for applications that require concurrent networking operations.
API Features
The WinInet API is built on top of the Windows Sockets protocol and can be categorized into four main function categories: General-purpose WinInet functions, WinInet File Transfer Protocol (FTP) functions, WinInet Gopher functions, and WinInet HyperText Transfer Protocol (HTTP) functions.
These functions are exported from a redistributable dynamic link library called the WININET.DLL, which can be redistributed with Win32 applications.
The WinInet API functions provide a high-level interface that hides many of the complexities of programming Internet applications.
The Win32 Internet functions are similar to traditional Win32 functions in how they handle elements such as buffer management and error returns.
The Win32 Internet functions are fully "reentrant" and multithread safe, allowing multithreaded applications to make simultaneous calls into the functions from different threads without adverse effects.
Here are the key advantages of using the WinInet API:
- No need to know TCP/IP and Windows Sockets.
- No need to know Internet protocols.
- Constant set of functions in an environment of rapidly changing and evolving protocols.
- Win32 function standards.
- Full access to Internet protocols.
- High-performance, multithreaded Internet applications.
- Persistent caching support built in.
The Win32 Internet functions provide persistent caching for all protocols, allowing your application development to focus on the data itself, rather than on managing the data-cache.
Networking
Networking is a crucial aspect of wininet. Wininet uses the Berkeley sockets interface to provide networking functionality.
Wininet supports multiple protocols, including HTTP, HTTPS, and FTP. This allows developers to create applications that can communicate with various servers and services.
To establish a network connection, wininet uses the WSAAccept function, which returns a socket handle that can be used for further communication.
TCP/IP and Sockets
TCP/IP and Sockets can be a daunting topic, but the WinInet API makes it much more accessible.
The WinInet API converts TCP/IP and Windows Sockets into task-oriented functions that use the familiar Win32 API function style. This means you don't need to write WinSock code directly.
You don't need to be familiar with the TCP/IP protocol to use the WinInet API, as it transparently executes WinSock functions for you. This is a huge advantage for developers who want to focus on higher-level programming tasks.
Wow64
Wow64 is a compatibility layer in 64-bit Windows that allows 32-bit applications to run seamlessly. It's essentially a bridge between the two, enabling 32-bit code to interact with 64-bit Windows components.
One key aspect of Wow64 is that it doesn't significantly impact the behavior of WININET, which is a crucial component for network communication. WININET is not sufficiently low-level that the 32-bit builds of WININET.DLL for 64-bit Windows differ from the corresponding builds in 32-bit Windows.
Functions
The WinInet API functions provide a range of services for interacting with the Internet, including Gopher, FTP, and HTTP.
The Gopher functions provide a standard interface to the Gopher specification, allowing you to find resources on the Internet and retrieve them without knowing their location. There are several Gopher functions, including GopherAttributeEnumerator(), GopherCreateLocator(), and GopherGetAttribute().
The Gopher functions can be used to create a Gopher or Gopher+ locator string, locate documents, binary files, index servers, or directory trees, and retrieve specific attribute information from a Gopher server.
Here are some of the Gopher functions listed:
Multithreaded Application Support
The WinInet API functions are fully multithread safe, which means you can make simultaneous calls to them from multiple threads without worrying about synchronization problems or deadlock.
This is a huge advantage, as it allows you to write more efficient and scalable code. You can easily make multiple requests at the same time, without having to worry about the underlying mechanics.
The WinInet functions handle all multithread synchronization internally, so you don't have to worry about writing complex synchronization code.
Http Functions

Http functions are used to control the transmission and content of HTTP requests. They provide a standard interface to the HTTP specification.
The WinInet HTTP functions are used for the Web and control the transmission and content of HTTP requests. The HttpAddRequestHeaders() function adds one or more HTTP request headers to the HTTP request handle, while the HttpOpenRequest() function opens an HTTP request handle.
To open an HTTP request handle, you need to call the HttpOpenRequest() function, which takes several parameters, including the handle to an HTTP session returned by InternetConnect(), the verb to use in the request, the name of the target object, the HTTP version, the referer, the content types accepted by the client, and flags and context values.
The HttpSendRequest() function sends the specified request to the HTTP server, and the HttpQueryInfo() function queries for information about an HTTP request. These functions work together to open a file, in this case, the file stored in the m_strPath class data member.

Here are some key flags that can be used with the HttpOpenRequest() function:
These flags can be used to customize the behavior of the HttpOpenRequest() function and the HttpSendRequest() function.
Plugins and Options
To use the WinInet plugin with gSOAP, you'll need to add the gsoapWinInet2.h and gsoapWinInet2.cpp files to your project. If you have a C project, change the extension to .c.
You'll also need to register the WinInet plugin with soap_register_plugin(soap, wininet_plugin) after creation and initialization of the soap context.
To specify HTTP proxy settings, set the soap.proxy_host and soap.proxy_port to the HTTP proxy host and port, respectively, and optionally set soap.proxy_userid and soap.proxy_passwd to authenticate to the proxy.
The receive and send timeouts limit the time to receive and send data, respectively. This behavior differs from the gSOAP engine's timeouts that limit the socket receive and send operation idle times.
To control the WinInet's HttpOpenRequest options, you can register the WinInet plugin with soap_register_plugin_arg() and supply an argument that is passed on to HttpOpenRequest. For example:
- INTERNET_FLAG_KEEP_CONNECTION use keep-alive semantics, if available, for the connection.
- INTERNET_FLAG_IGNORE_CERT_CN_INVALID disables Microsoft Win32 Internet function checking of SSL/PCT- based certificates that are returned from the server against the host name given in the request.
- INTERNET_FLAG_IGNORE_CERT_DATE_INVALID disables Win32 Internet function checking of SSL/PCT-based certificates for proper validity dates.
Note that if there are errors in sending the HTTP request, a dialog box will be displayed by the library.
Sample and Usage
The RAWHTML.EXE program is a great example of how to use the WININET.DLL library for HTTP data transfer. It's a simple sample that demonstrates the basic usage of these functions to create Internet-enabled applications for Win32.
This program takes a URL input by a user and requests HTML data from the URL-specified server. The data returned via the WinInet functions is then displayed as raw HTML in a multiple-line edit control.
The RAWHTML program is a dialog-based application that contains three classes: CRawHtmlApp, CRawHtmlDlg, and CAboutDlg. The CRawHtmlDlg class contains the meat of the application's functionality.
The program can be found in the SOURCE\CHAP17\RAWHTML folder on this book's companion CD-ROM. This includes all of its source files, making it easy to study and learn from.
To run the RAWHTML program, you'll need to have the WININET.DLL library installed on your system. This library provides the necessary functions for HTTP data transfer.
Here are the three classes used in the RAWHTML program:
- CRawHtmlApp: Contains the minimum necessary code to get the application running.
- CRawHtmlDlg: Contains the meat of the application's functionality.
- CAboutDlg: A trivial About box class.
Advantages of API

The WinInet API provides a high-level interface that hides the complexity of programming Internet applications. This means you don't have to worry about the underlying protocols and can focus on developing your application.
The API converts Internet protocols into task-oriented functions, so you don't need to write Windows Sockets code or be familiar with TCP/IP. This makes it easier to develop Internet client applications.
One of the biggest advantages of using the WinInet API is that it provides persistent caching support for all Internet protocols. This means your application can focus on obtaining data, rather than managing the cache.
The API provides a constant set of functions, so you don't need to update your applications every time the underlying protocol changes. This includes advanced protocols like HTTP version 1.1, which can be implemented without changing applications.
Here are some of the key advantages of using the WinInet API:
- No need to know TCP/IP and Windows Sockets
- No need to know Internet protocols
- Constant set of functions in an environment of rapidly changing and evolving protocols
- Full access to Internet protocols
- High-performance, multithreaded Internet applications
- Persistent caching support built in
The WinInet API is designed to make Internet client applications easier to write, not to facilitate writing Internet servers. This is because servers require control over how the protocol is accessed and how I/O is performed to achieve high performance.
Frequently Asked Questions
What is the difference between WinHTTP and WinInet?
WinHTTP is designed for making HTTP and HTTPS requests, while WinINet is a more general-purpose API that supports a broader range of internet protocols. This difference makes WinHTTP a more efficient solution for web-related tasks.
Is WinInet deprecated?
Yes, WinInet is deprecated for HTTP, HTTPS, and FTP URIs on Windows. However, it's still supported for FTP URIs, but a newer method, libcurl, is now the default.
Does Chrome use WinInet?
Yes, Chrome uses WinInet on Windows to interpret proxy settings. This ensures consistency with other WinInet-based applications, like Internet Explorer.
Featured Images: pexels.com
