共用方式為


CInternetConnection Class

 

The new home for Visual Studio documentation is Visual Studio 2017 Documentation on docs.microsoft.com.

The latest version of this topic can be found at CInternetConnection Class.

Manages your connection to an Internet server.

Syntax

class CInternetConnection : public CObject  

Members

Public Constructors

Name Description
CInternetConnection::CInternetConnection Constructs a CInternetConnection object.

Public Methods

Name Description
CInternetConnection::GetContext Gets the context ID for this connection object.
CInternetConnection::GetServerName Gets the name of the server associated with the connection.
CInternetConnection::GetSession Gets a pointer to the CInternetSession object associated with the connection.

Public Operators

Name Description
CInternetConnection::operator HINTERNET A handle to an Internet session.

Remarks

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.

Inheritance Hierarchy

CObject

CInternetConnection

Requirements

Header: afxinet.h

CInternetConnection::CInternetConnection

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.

CInternetConnection::GetContext

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.

CInternetConnection::GetServerName

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.

CInternetConnection::GetSession

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.

CInternetConnection::operator HINTERNET

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

operator HINTERNET() const;  

See Also

CObject Class
Hierarchy Chart