Looping in Win32 GUI Applications

Hey Guys,

I've been browsing this forum a while and decided to sign up, looks like a good place for help.

I'm new to C++, possibly been coding it about 1 week now and I've decided to make a IP Messenger.

I've got the code all worked out for getting an IP from the user, getting a Port, deciding if the user wants to host or connect to a host (if this makes any sense to you).

Anyway, what I have is a little problem creating loops, with Win32 when you create a while loop to say loop while variable A is set to TRUE then the application / dialog form crashes and I am unable to use it.

Another thing is, when you tell the application to run as a server, you tell it to accept the socket, for when the client connects, but the application stops responding, until the client connects, then jumps back into life!

For the loop, I'm after using the Recv() function from WinSock2.h to keep polling for new data from the client / server, for new messages transmitted which will then be displayed on a list. This will probably make more sense if you look at my code.

Bare in mind, my code will be scruffy, since I've thrown all this together from guides etc... as a starting point in C++.

I've been looking at the GetMessage() loop but I keep getting compile errors. What would be the best way in doing this?

Also don't take note of all the libraries I've included haha, that was when I was just testing different functions and things to include, never removed them once I was finished.



Main.cpp : http://www.pastebin.ca/raw/2390637
Resource.h : http://www.pastebin.ca/raw/2390637
Resource.rc : http://www.pastebin.ca/raw/2390640
After a little more playing, I've noticed that even if I don't loop, my application crashes. Say I listen for data with the recv() function, it will crash the program, until that data is received, if that makes sense.

Along with crashing the program until someone accepts the socket connection.

How do I get around this, can I now make some kind of side process to handle these options to always keep the gui free and responsive?
I have not really looked though your code, but...

can I now make some kind of side process

Yes -- you can create a thread using either CreateThread or, if you are using CRT functions from the thread, rather than just Win32 calls, _beginthreadex


PS To get an IP address, you could use an IP Address Control, rather than doing it freestyle?

About IP Address Controls
Last edited on
Topic archived. No new replies allowed.