Todd Todd - 1 year ago 107
C++ Question

Windows message loop and server loop

I made a window using WinAPI and it needs to enter message loop:

while (GetMessage(&msg, nullptr, 0, 0))

Now how do I create a server and start receiving clients, if my main thread is processing UI messages?
I tried putting all server code in
and call
but it just crashes with:

Exception thrown at 0x00000000 in test.exe: 0xC0000005:
Access violation executing location 0x00000000.

Any help would be appreciated.

Answer Source

This is a very confusing question as it asks one question in the title, but the content addresses a different problem (threads crashing).

To address the primary question: Microsoft did add a way to handle socket communications in a GUI thread friendly way: WSAAsyncSelect. This will send socket events as messages to your applications message queue - typically an invisible window is created to handle the messages.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download