Async Delegate

G

Guest

hi, im trying to create a delagte for my async socket program but i cant
figure out how to create the async delegate for it. heres what i have so
far...

AsyncCallback * conasync = new AsyncCallback(0, this->ConnectCallBack);

heres my error:

x:\User\FinalProject\Battleship\NewGame.h(158): error C3351:
'System::AsyncCallback' : if you pass a NULL object instance to a delegate
constructor you must also pass the address of a static member function


it was very simple in VB but im seeing now its not quite as simple in
C++...if anyone can help me out thatd be great.

thanks
 
C

Carl Daniel [VC++ MVP]

iwdu15 said:
hi, im trying to create a delagte for my async socket program but i cant
figure out how to create the async delegate for it. heres what i have so
far...

AsyncCallback * conasync = new AsyncCallback(0, this->ConnectCallBack);

new AsyncCallback(0, &YourClass::ConnectCallBack);

-cd
 
P

Peter Oliphant

AsyncCallback * conasync = new AsyncCallback(0, this->ConnectCallBack);
new AsyncCallback(0, &YourClass::ConnectCallBack);

I would have thought it was this:

new AsyncCallback( this, ClassName::ConnectCallBack ) ;

but I'm now working in the new syntax, and my memory is weak... :)

[==P==]
 
C

Carl Daniel [VC++ MVP]

Peter Oliphant said:
I would have thought it was this:

new AsyncCallback( this, ClassName::ConnectCallBack ) ;

but I'm now working in the new syntax, and my memory is weak... :)

It'd be 0 if the callback is static, or 'this' if it's not static.

-cd
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top