How do I reference a CAsyncSocket class (or how do I copy this class);

Posted on 2003-03-10
Medium Priority
Last Modified: 2013-11-20
I have a class that brings up a window and realises a connection with another computer using CAsyncSocket... After connection I want to destroy that window(implicitly the class) and to copy the connected socket to another class so I can work with it.
For example I use a dialog for simplicity in this example:

---implemantation of some class---
--some function--
CMyDialog dlg;
    //how do I do this here:
    //where socket: is declared as CMyAsyncSocket in this class
    //and socketdlg: is declared as CMyAsyncSocket in CMyDialog

---in other function of this class---
Question by:lbalan79
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
LVL 48

Expert Comment

ID: 8102124
I think it's better to declare CMyAsyncSocket somewhere outside of dialog class. Keep pointer to this socket in the dialog:

class CMyClass
    CMyAsyncSocket m_socket;

void CMyClass::ShowConnectionDlg()
    CMyDialog dlg;
    dlg.m_pSocket = &m_socket;
        // continue to work with m_socket

class CMyDialog : public CDialog
    CMyAsyncSocket* m_pSocket;  // filled by caller before DoModal
LVL 12

Accepted Solution

williamcampbell earned 750 total points
ID: 8104239

 class CDlg1
    CAsyncSocket m_sock1;

    CopySocket ( SOCKET& sock )
       m_sock1.Attach ( sock );

 class CDlg2
    CAsyncSocket m_sock2;

    SOCKET GetSocket () { m_sock2.Detach (); }

 CDlg1 dlg1;
 CDlg2 dlg2;

 dlg1.CopySocket ( dlg2.GetSocket () );

 Try That

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
Suggested Courses
Course of the Month12 days, 14 hours left to enroll

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question