(You don't mention what type of operations you want to use WinInet for--FTP,
HTTP, etc.--so I'll assume HTTP.)
Keep in mind that WinInet was designed only for single-user desktop client
applications. Do not use WinInet in any kind of multi-user or server-based
application, or NT service. For those kind of applications, you should use
either the .NET Framework or the WinHTTP API instead.
Within a single-user application or component, it is OK to send HTTP
requests concurrently across multiple threads with WinInet. You do not need
to serialize access to the InternetOpen and InternetConnect handles when
creating new HTTP request handles. WinInet handles do not have any thread
affinity, so you can access the same handle from different threads. However,
once an HTTP request is in-progress, you should be careful with
multithreaded access to the HTTP request handle.
During the HTTP request, it is a good idea to serialize access to the
WinInet request handle. In particular, you should avoid calling
InternetCloseHandle from another thread to abort an HTTP request that is
in-progress. To abort an HTTP request, close the request handle during a
callback (meaning you'll need to set a callback function on the request
handle via InternetSetStatusCallback).
If your application is going to send a lot of concurrent HTTP requests
simultaneously across multiple threads, then you should consider turning off
the WinInet cache (by specifying the INTERNET_FLAG_RELOAD and
INTERNET_FLAG_NO_CACHE_WRITE flags in the call to HttpOpenRequest).
Also note that by default, WinInet will limit the number of simultaneous
connections to a given server (or proxy) to 2 simultaneous connections, per
the HTTP/1.1 specification. So if you try to send more than two requests to
the same server, WinInet will let two of the requests go through and block
the others. (This limit can be overridden using the
INTERNET_OPTION_MAX_CONNS_PER_SERVER and _MAX_CONNS_PER_1_0_SERVER options).
If you do experience instability using WinInet in multithreaded scenarios,
then switch to WinHTTP. WinHTTP also does not have the default
2-simultaneous connection limit.
Hope that helps.
"Jan Plastenjak" <no...@ms.com> wrote in message