CInternetConnection Class

 

For the latest documentation on Visual Studio 2017 RC, see Visual Studio 2017 RC Documentation.

Manages your connection to an Internet server.

class CInternetConnection : public CObject  

Public Constructors

NameDescription
CInternetConnection::CInternetConnectionConstructs a CInternetConnection object.

Public Methods

NameDescription
CInternetConnection::GetContextGets the context ID for this connection object.
CInternetConnection::GetServerNameGets the name of the server associated with the connection.
CInternetConnection::GetSessionGets a pointer to the CInternetSession object associated with the connection.

Public Operators

NameDescription
CInternetConnection::operator HINTERNETA handle to an Internet session.

It is the base class for MFC classes CFtpConnection, CHttpConnection, and CGopherConnection. Each of these classes provides additional functionality for communicating with the respective FTP, HTTP, or gopher server.

To communicate directly with an Internet server, you must have a CInternetSession object and a CInternetConnection object.

To learn more about how the WinInet classes work, see the article Internet Programming with WinInet.

CObject

CInternetConnection

Header: afxinet.h

This member function is called when a CInternetConnection object is created.

CInternetConnection(
    CInternetSession* pSession,  
    LPCTSTR pstrServer,  
    INTERNET_PORT nPort = INTERNET_INVALID_PORT_NUMBER,  
    DWORD_PTR dwContext = 1);

Parameters

pSession
A pointer to a CInternetSession object.

pstrServer
A pointer to a string containing the server name.

nPort
The number that identifies the Internet port for this connection.

dwContext
The context identifier for the CInternetConnection object. See Remarks for more information about dwContext.

Remarks

You never call CInternetConnection yourself; instead, call the CInternetSession member function for the type of connection you want to establish:

The default value for dwContext is sent by MFC to the CInternetConnection-derived object from the CInternetSession object that created the InternetConnection-derived object. The default is set to 1; however, you can explicitly assign a specific context identifier in the CInternetSession constructor for the connection. The object and any work it does will be associated with that context ID. The context identifier is returned to CInternetSession::OnStatusCallback to provide status on the object with which it is identified. See the article Internet First Steps: WinInet for more information about the context identifier.

Call this member function to get the context ID for this session.

DWORD_PTR GetContext() const;  

Return Value

The application-assigned context ID.

Remarks

The context ID is originally specified in CInternetSession and propagates to CInternetConnection- and CInternetFile-derived classes, unless specified differently in the call to a function that opens the connection. The context ID is associated with any operation of the given object and identifies the operation's status information returned by CInternetSession::OnStatusCallback.

For more information about how GetContext works with other WinInet classes to give the user status information, see the article Internet First Steps: WinInet for more information about the context identifier.

Call this member function to get the name of the server associated with this Internet connection.

CString GetServerName() const;  

Return Value

The name of the server this connection object is working with.

Call this member function to get a pointer to the CInternetSession object that's associated with this connection.

CInternetSession* GetSession() const;  

Return Value

A pointer to a CInternetSession object associated with this Internet connection object.

Use this operator to get the API-level handle for the current Internet session.

operator HINTERNET() const;  

CObject Class
Hierarchy Chart

Show: