Click here to Skip to main content
15,883,883 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: MFC type of file Pin
John M. Drescher29-Oct-04 6:06
John M. Drescher29-Oct-04 6:06 
GeneralRe: MFC type of file Pin
missnazar29-Oct-04 6:21
missnazar29-Oct-04 6:21 
GeneralRe: MFC type of file Pin
Maximilien29-Oct-04 7:38
Maximilien29-Oct-04 7:38 
GeneralRe: MFC type of file Pin
alex.barylski29-Oct-04 14:13
alex.barylski29-Oct-04 14:13 
GeneralThread message queue Pin
GingerSpen29-Oct-04 6:01
GingerSpen29-Oct-04 6:01 
GeneralRe: Thread message queue Pin
Michael Dunn29-Oct-04 6:58
sitebuilderMichael Dunn29-Oct-04 6:58 
GeneralRe: Thread message queue Pin
GingerSpen29-Oct-04 7:36
GingerSpen29-Oct-04 7:36 
GeneralRe: Thread message queue Pin
GKarRacer29-Oct-04 7:03
GKarRacer29-Oct-04 7:03 
MSDN indicates that windows creates a message queue along with each thread that is created

That's not exactly true. Threads only have a message queue if they call one of the thread processing functions, such as GetMessage, PeekMessage, or create a window.

Therefore can I use the thread's message queue to receive message based socket notifications

Yes, absolutely. It is easy to use a background thread to handle socket communication. But, before I give a brief description of how to handle Async sockets, I should mention there is a better method. Use event based sockets (WSAEventSelect instead of WSAAsyncSelect). The performance for event based is tremendously better than for async sockets. Message processing uses a lot of overhead. If your data load is small, then it won't matter too much which way you go, but if you expect high data streams, async sockets simply won't keep up.

Note: MFC's CAsyncSocket does not support event based, but it is not as hard to do it by hand as it may seem).

Now for async sockets:
Create your background thread. Inside your thread, create a non-visible window as a child of your main window. Use this background window to receive all socket notifications. In other words, pass this window handle to the AsyncSelect function.

If you're using MFC, create a CWinThread derived class. Use this class for the AfxCreateThread function. Inside the InitInstance function for this thread class, create your window and set it as the m_pMainWnd for the thread (just like what happens with CWinApp and CMainFrame). The built-in "Run" function will properly handle the message processing. Now just add an appropriate ON_MESSAGE handler to your background window class (just derive from CWnd).
GeneralRe: Thread message queue Pin
GingerSpen29-Oct-04 7:34
GingerSpen29-Oct-04 7:34 
GeneralRe: Thread message queue Pin
GKarRacer29-Oct-04 9:58
GKarRacer29-Oct-04 9:58 
GeneralRe: Thread message queue Pin
GingerSpen2-Nov-04 11:08
GingerSpen2-Nov-04 11:08 
GeneralRegarding declaration of objects Pin
Member 12881529-Oct-04 6:00
Member 12881529-Oct-04 6:00 
GeneralRunning a mdb from Visual C++ Pin
Rhina29-Oct-04 5:49
Rhina29-Oct-04 5:49 
GeneralRe: Running a mdb from Visual C++ Pin
David Crow29-Oct-04 5:58
David Crow29-Oct-04 5:58 
GeneralRe: Running a mdb from Visual C++ Pin
John M. Drescher29-Oct-04 5:59
John M. Drescher29-Oct-04 5:59 
GeneralRe: Running a mdb from Visual C++ Pin
Rhina29-Oct-04 6:10
Rhina29-Oct-04 6:10 
GeneralMFC Remote Drive Access Pin
missnazar29-Oct-04 5:38
missnazar29-Oct-04 5:38 
GeneralRe: MFC Remote Drive Access Pin
David Crow29-Oct-04 5:59
David Crow29-Oct-04 5:59 
GeneralRe: MFC Remote Drive Access Pin
missnazar29-Oct-04 6:05
missnazar29-Oct-04 6:05 
GeneralRe: MFC Remote Drive Access Pin
David Crow29-Oct-04 7:17
David Crow29-Oct-04 7:17 
GeneralRe: MFC Remote Drive Access Pin
John M. Drescher29-Oct-04 6:16
John M. Drescher29-Oct-04 6:16 
Generalrandom colored letters from a CString Pin
...---...29-Oct-04 4:52
...---...29-Oct-04 4:52 
GeneralRe: random colored letters from a CString Pin
Antony M Kancidrowski29-Oct-04 5:32
Antony M Kancidrowski29-Oct-04 5:32 
GeneralRe: random colored letters from a CString Pin
David Crow29-Oct-04 5:33
David Crow29-Oct-04 5:33 
GeneralRe: random colored letters from a CString Pin
LeeeNN29-Oct-04 10:58
LeeeNN29-Oct-04 10:58 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.