|
-
May 24th, 2008, 08:01 AM
#1
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!
Last edited by Chirieac; May 24th, 2008 at 08:03 AM.
I love this forum. Thanks all for your help!
-
May 24th, 2008, 08:08 AM
#2
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....
TheCPUWizard is a registered trademark, all rights reserved. (If this post was helpful, please RATE it!)
2008, 2009,2010
In theory, there is no difference between theory and practice; in practice there is.
* Join the fight, refuse to respond to posts that contain code outside of [code] ... [/code] tags. See here for instructions 
* How NOT to post a question here
* Of course you read this carefully before you posted
* Need homework help? Read this first
-
May 24th, 2008, 08:22 AM
#3
Re: WSAAsyncSelect and virtual functions
Thnks mister Wizard! I will try that... Bye!
I love this forum. Thanks all for your help!
-
May 24th, 2008, 08:30 AM
#4
Re: WSAAsyncSelect and virtual functions
Now, doing that I get an error on my main message while loop, at DispatchMessage (&msg) ;
Weird stuff...
I love this forum. Thanks all for your help!
-
May 24th, 2008, 04:28 PM
#5
Re: WSAAsyncSelect and virtual functions
 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.
henky
----------------------------------
[email protected] is not my email address anymore...
Jangan Pernah Menyerah
-
May 24th, 2008, 04:37 PM
#6
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?
I love this forum. Thanks all for your help!
-
May 24th, 2008, 05:00 PM
#7
Resolved
Stupid me... I've created the socket class in a function and guess what? After the function return the class object was deleted! On FD_WRITE when I try to get that class instance pointer, that pointer now contains garbage data....
But why if I make OnAccept non-virtual I still can access that function through that "invalid" pointer and get no errors?
Sorry guys (TheCPUWizard, [email protected]) for my useless post... I hope that in the future I will make better posts that other persons can learn from.
Thanks and sorry, Bye!
I love this forum. Thanks all for your help!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|