Hinweis
Für den Zugriff auf diese Seite ist eine Autorisierung erforderlich. Sie können versuchen, sich anzumelden oder das Verzeichnis zu wechseln.
Für den Zugriff auf diese Seite ist eine Autorisierung erforderlich. Sie können versuchen, das Verzeichnis zu wechseln.
BOOLAttach(SOCKEThSocket**);**
Return Value
Nonzero if the function is successful.
Parameters
hSocket
Contains a handle to a socket.
Remarks
Call this member function to attach the hSocket handle to a CSocket object. The SOCKET handle is stored in the object’s m_hSocket data member.
For more information, see and related articles in Visual C++ Programmer’s Guide. Also see in the Win32 SDK documentation.
Example
// ...
class CSockThread : public CWinThread
{
// ... Other function and member declarations
protected:
CSocket m_sConnected;
};
SOCKET hConnected;
BOOL CSockThread::InitInstance()
{
// Attach the socket object to the socket handle
// in the context of this thread.
m_sConnected.Attach(hConnected);
return TRUE;
}
// This listening socket has been constructed
// in the primary thread.
void CListeningSocket::OnAccept(int nErrorCode)
{
// This CSocket object is used just temporarily
// to accept the incoming connection.
CSocket sConnected;
Accept(sConnected);
// Detach the newly accepted socket and save
// the SOCKET handle.
hConnected = sConnected.Detach();
// After detaching it, it should no longer be
// used in the context of this thread.
// Start the other thread.
AfxBeginThread(RUNTIME_CLASS(CSockThread));
}
CSocket Overview | Class Members | Hierarchy Chart
See Also CAsyncSocket::Attach