Winsock and Winapi implementation?

Hello people
I am trying to implement a win32/winapi client with winsock to connect to a server program.

What is the best way to integrate the winsock functions/etc with winapi?
For ex. Where should i declare my wsadata? In the winmain? Above winmain?
Using another thread? (_beginthreadex?)

Should I separate my main.cpp into multiple files? If so, how would i go about this? Which parts are appropriate to separate?

I know all of this syntax but have no idea how to implement them correctly.

Here is my code at the moment, but im not sure if it is being implemented correctly?

Youll see some code constructing an email object, just ignore it.

Main.cpp:
http://pastebin.com/1JfmWTLU

Also can anyone review my code for criticism?
Im a learner and I want to get criticised.

Lines to look at: 562, 172, 50, 39, 40
Also, is my implementation of textboxes, and retrieveing their data correct?
It all works, but i want to do this the Right Way.

Thanks all for the help!
Where should i declare my wsadata? In the winmain? Above winmain?
WSAStartup() should be called once, you don't need to keep the WSADATA hanging around, so doing it all in WinMain() is fine. Certainly, not in another thread.

Should I separate my main.cpp into multiple files?
Usually, yes.

If so, how would i go about this? Which parts are appropriate to separate?
That depends on your design.

Having looked at the code, I'd put each of those dialogs into a seperate module to begin with.

Don't use GlobalAlloc/GlobalFree. They're WIN16 memory management class (and you're missing the redunanct GlobalLock/GlobalUnlock calls that go with them. You can juse use new/delete as you would for any C++ object or if you want to use the Windows stuff, your create a local heap with HeapCreate, then allocate using HeapAlloc/HeapFree.
Last edited on
How would i go about putting each dialog box in a different module? What is a module?
By module do u mean different cpp files?
Last edited on
Yes.
Topic archived. No new replies allowed.