MFC support for Sockets.
SCS.007@mch.scn.de Tuesday, December 24, 1996 Environment : VC++ 1.52, Windows 3.11 - Might be applicable to ALL versions of MFC and Windows. Hi All, I want to start a discussion on the MFC support for sockets. I have gone thru the src code and this is the info I've found. * Every MFC application has to call AfxSocketInit() b'for it can create socket objects( CAsyncSocket etc). This calls WSAStartUp and also creates a new object of type AFX_SOCKSTATE, the definition of which is given below. struct AFX_SOCKSTATE // AUXVARS.H { void (FAR* lpfnSockCleanup)(); HWND hSocketWindow; CMapWordToPtr mapSocketHandle; CMapWordToPtr mapDeadSockets; CPtrList listSocketNotifications; }; // It's self explanatory to people who have worked with sockets. My comment. * After this, any call to CAsyncSocket::Create() shows the following sequence of func calls. Create() { Socket() { CAsyncSocket::AttachHandle { // LookUp Handle in list. // If first time, create new window. // add socket to map in _afxSocketState } CAsyncSocket::AsyncSelect() { WSAAsyncSelect(...)// Here a window handle has to be specified which will recv mesgs such as FD_READ, FD_WRITE... } } } What I don't understand is, why is a new Window being created every time an application calls AfxSocketInit(). Okay, I agree that everything works fine, but why create a new window for every application that wants to use sockets, when the same support could have been provided with just one window. I'd really appreciate it if someone cleared this up for me. There must be some reason why the MFC team did this. Best Regards, Chandru.
Donald C. Asonye -- donald@menudo.uh.edu Friday, December 27, 1996 [Mini-digest: 2 responses] > > Environment : VC++ 1.52, Windows 3.11 - Might be applicable to ALL versions > of MFC and Windows. > > Hi All, > > I want to start a discussion on the MFC support for sockets. I have gone thru > the src code and this is the info I've found. > > * Every MFC application has to call AfxSocketInit() b'for it can create > socket objects( CAsyncSocket etc). This calls WSAStartUp and also creates a > new object of type AFX_SOCKSTATE, the definition of which is given below. [source snipped] > > What I don't understand is, why is a new Window being created every time an > application calls AfxSocketInit(). Okay, I agree that everything works fine, > but why create a new window for every application that wants to use sockets, > when the same support could have been provided with just one window. I'd > really appreciate it if someone cleared this up for me. There must be some > reason why the MFC team did this. Complexity. Why make things complicated when it does not have to be? It is simpler to have a window per application. Winsock functions such as WSAAsyncSelect() needs a window to send messages to. It is faster and easily managed if the window that receives the messages is unique for every application. If not, then mfc would have to do a lot of other things. One more thing is: who knows how many applications will use a socket? There is no way to determine this. The message handler would be very complicated and long if it had to handle messages for every application. Would you like to have one single window procedure that handles all messages for all windows applications, no matter what type of application or message it is? > > Best Regards, > Chandru. > By the way, I think it might be a good idea if you play with the winsock api first before jumping to mfc socket classes. That is if you have not done so already. Take care, -- Donald ************************************************** * Pull me under. * * Pull me under, I am not afraid -Dream Theater * ************************************************** Email :mailto:donald@uh.edu Samples :ftp://ftp.hpc.uh.edu/pub/donald WWW :http://www.uh.edu/~dasonye -----From: WnDBSoft@aol.com In a message dated 96-12-24 14:46:40 EST, you write: > What I don't understand is, why is a new Window being created every time an > application calls AfxSocketInit(). Okay, I agree that everything works fine, > > but why create a new window for every application that wants to use sockets, > > when the same support could have been provided with just one window. I'd > really appreciate it if someone cleared this up for me. There must be some > reason why the MFC team did this. > The hWndSocketNotification is a secret, hidden window the sockets create so that they can pseudo-receive and pusedo-send Windows messages to and from themselves and the rest of your application. This helps keep your program from freezing. Sincerely, Brian Hart WnDBSoft Software International http://members.aol.com/wndbsoft/
| Вернуться в корень Архива |