Re: passing this object



On Thu, 27 Nov 2008 01:25:29 -0800, "Jung, William"
<aopiyy001@xxxxxxxxx> wrote:

I would like to pass "this" object to a constructor of socket class -
Sock which extends CSocketComm.

Once the socket class processed the data, the socket class use the
reference of CVirtualScreen (this object) - screen.setMessage function
to pass back the message to CVirtualScreen.

Is the following a correct syntax of implementing it?

should I involve reference / pointer in this case?

Please advice the incorrect area of the following code.

===================
class CVirtualScreen
{
public:
CVirtualScreen();
~CVirtualScreen();
Sock *sock;
}
===================
CVirtualScreen::CVirtualScreen()
{
// QUESTION ///////////////////////////
// IS IT CORRECT WAY OF PASSING
// THIS OBJECT TO SOCKET CLASS??
// SHOULD I USE & REFERENCE??
// SHOULD I USE POINTER??
sock = new Sock(this);
}

// function must take std::string as parameter
CVirtualScreen::setMessage( std::string message )
{
//setMessage to queue
}
===================
class Sock : public CSocketComm
{
public:
Sock(CVirtualScreen screen);
~Sock();

// QUESTION ///////////////////////////
// DO I DECLARE REFERENCE TO CVirtuaqlScreen LIKE THIS WAY??
CVirtuaqlScreen screen;

virtual void OnDataReceived(const LPBYTE lpBuffer, DWORD dwCount);
bool StartServer();


};
===================
Sock::Sock(CVirtualScreen screen)
{
// QUESTION ///////////////////////////
// CAN I SET REFERENCE TO CVirtualScreen LIKE THIS??
// SHOULD I USE POINTER??
screenObject = screen
StartServer();
}
Sock::~Sock()
{
StopComm();
}
void Sock::OnDataReceived(const LPBYTE lpBuffer, DWORD dwCount)
{
// do some stuff and output the std::string object
std::string message = ... etc
// QUESTION ///////////////////////////
// ONCE SOCKET PROCESSED THE MESSAGE AND EXTRACT THE DATA
// SOCKET WILL PASS THE MESSAGE BACK TO CVirtualScreen TO
// INSERT MESSAGE INTO A MESSAGE QUEUE
// IS THE FOLLOWING COORECT SYNTAX TO PASS MESSAGE BACK TO
// CVirtualScreen CLASS??
screen.setMessage ( message );
}


I used a pointer syntax but I am still getting error
http://www.oniva.com/upload/1356/e.jpg

any idea what's wrong here?

the line of
void Create1(CVirtualScreen *Vscreen);
AND
CVirtualScreen *Vscreen;

is having problem

===============
Sock::Sock()
{
StartServer();
}

void Sock::Create1(CVirtualScreen *screen)
{
Vscreen = screen;
}

Sock::~Sock()
{
StopComm();
}
===============
class Sock : public CSocketComm
{
public:
Sock();
~Sock();
void Create1(CVirtualScreen *Vscreen);
CVirtualScreen *Vscreen;

};

.



Relevant Pages

  • Re: passing this object
    ... Sock which extends CSocketComm. ... Once the socket class processed the data, ... reference of CVirtualScreen - screen.setMessage function ...
    (microsoft.public.vc.language)
  • Re: passing this object
    ... Sock which extends CSocketComm. ... Once the socket class processed the data, ... reference of CVirtualScreen - screen.setMessage function ...
    (microsoft.public.vc.language)
  • Re: passing this object
    ... Sock which extends CSocketComm. ... Once the socket class processed the data, ... reference of CVirtualScreen - screen.setMessage function ...
    (microsoft.public.vc.language)
  • Re: passing this object
    ... Sock which extends CSocketComm. ... Once the socket class processed the data, ... reference of CVirtualScreen - screen.setMessage function ...
    (microsoft.public.vc.language)
  • Re: "invalid handle", sockets, threads and garbage collector
    ... your IntPtr value happens to coincide with a reference. ... The exception contains "invalid handle" message. ... Socket constructor problem ... finalization means closing the handle to resource. ...
    (microsoft.public.dotnet.framework.clr)