WSAAsyncSelect and virtual functions
Hello!
I'm trying to make an asynchronous socket class with WSAAsyncSelect.
I get an unhandled exception on this events when I call virtual functions like OnAccept from WndProc. I have the pointer for the instance of the class in the window:
Code:
SetWindowLong(hwnd, GWL_USERDATA, (long) ((LPCREATESTRUCT)lParam)->lpCreateParams);
If I try to connect to a socket that is listening I get an error.
If I remove the keyword virtual from the function and try now to connect the Onaccept is called with no problem, but I need those function to be virtual.
What is the problem?
Thanks for reading my post, bye!
Re: WSAAsyncSelect and virtual functions
Remember....
A non-virtual function has a "real" address.
A virtual function is located indirectly via a lookup table (vTable) and can change based upon the objects actual type.
What is wrong with having a NON-virtual function in your base class which simply calls the virtual function. This will isolate the "virtuality" of the actual function....
Re: WSAAsyncSelect and virtual functions
Thnks mister Wizard! I will try that... Bye!
Re: WSAAsyncSelect and virtual functions
Now, doing that I get an error on my main message while loop, at DispatchMessage (&msg) ;
Weird stuff...
Re: WSAAsyncSelect and virtual functions
Quote:
Originally Posted by Chirieac
Hello!
...I call virtual functions like OnAccept from WndProc...
OnAccept() shouldn't be called by application. It should be called by framework.
Re: WSAAsyncSelect and virtual functions
Well, WSAAsyncSelect send a custom message to a window and the LOWORD of the lParam contains one of FD_xxx events (like FD_ACCEPT). On FD_ACCEPT I must call the function OnAccept, right? Is there another way?