need help!!! can not use some basic socket code!! Topic is solved

Do you have a question about makefiles, a compiler or IDE you are using and need to know how to set it up for wxWidgets or why it doesn't compile but other IDE's do ? Post your questions here.
Post Reply
czczzzz
Earned a small fee
Earned a small fee
Posts: 15
Joined: Thu May 13, 2021 10:34 am

need help!!! can not use some basic socket code!!

Post by czczzzz » Thu May 13, 2021 10:48 am

hello
I am a beginner at wxWidgets and I just (almost) finished my UI for my UDP client....panel..sizer..list...button...they work great!

I just want to use some really baisc socket code

like WSAStartup and addrinfo.......

But I can not include winsock2.h! it will give me a lot of error.

my tiny c code UDP client is fully finished and work well......i just want it have a wxWidgets UI.

but I even can not do a WSAStartup(MAKEWORD(2, 2), &d).....and no define for addrinfo........

Need help please! and sorry for my english


-------------------------------------------------------------------------------------------
version should be 3.15
Last edited by DavidHart on Thu May 13, 2021 10:58 am, edited 1 time in total.
Reason: Moderator: Removed multiple exclamation marks etc e.g. !!!!!!!!!!a lot of error!!!!!!!!!!a lot of error!!!!!!!!!!

User avatar
doublemax
Moderator
Moderator
Posts: 16189
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: need help!!! can not use some basic socket code!!

Post by doublemax » Thu May 13, 2021 11:31 am

czczzzz wrote:
Thu May 13, 2021 10:48 am
But I can not include winsock2.h! it will give me a lot of error.
I assume you mean compiler errors? If yes, which ones?

Try including <wx/msw/wrapwin.h> either instead of winsock2.h or before it.

Also experiment with include order, e.g. first all wx classes, then others. Or vice versa.
Use the source, Luke!

PB
Part Of The Furniture
Part Of The Furniture
Posts: 3062
Joined: Sun Jan 03, 2010 5:45 pm

Re: need help!!! can not use some basic socket code!!

Post by PB » Thu May 13, 2021 12:38 pm

I am not saying this is related, but until v3.1.6 wxWidgets by default builds with WinSock 1. See define wxUSE_WINSOCK2 in WXDIR/msw/setup.h and in the library folder.

I do not think you can mix two WinSock version in one application but I may be wrong.

New Pagodi
Super wx Problem Solver
Super wx Problem Solver
Posts: 392
Joined: Tue Jun 20, 2006 6:47 pm
Contact:

Re: need help!!! can not use some basic socket code!!

Post by New Pagodi » Thu May 13, 2021 1:08 pm

As PB said, until very recently, wxWidgets used winsock1 by default to ensure applications would work even with really old systems. It's a well known issue that if you try to use include both winsocke2.h (as you are with you're application) and winsock.h (which wxWidgets will) you need to include winsock2.h first.

But you can't simply do this with wxWidgets because if you have to include any windows headers, they should be included last - but as said above you need to include winsock2.h first. There are a few ways out of this viscous circle
1) if possible use the latest version from git. If you can do this, this is the simplest solution.
2) edit <wxroot>\include\msw\setup.h to and change "#define wxUSE_WINSOCK2 0" to "#define wxUSE_WINSOCK2 1" and then rebuild wxWidgets.

If neither of those are possible, you must be realy, really careful with the way headers are included in every file in your project
-before any #include statements add either '#define WIN32_LEAN_AND_MEAN' or '#define _WINSOCKAPI_'
-then include any wxWidgets headers you need
-finally include winsock2.h

This order is really important and can't be changed.

czczzzz
Earned a small fee
Earned a small fee
Posts: 15
Joined: Thu May 13, 2021 10:34 am

Re: need help!!! can not use some basic socket code!!

Post by czczzzz » Thu May 13, 2021 2:58 pm

WIN32_LEAN_AND_MEAN and _WINSOCKAPI_ They both work!

I am using vs2019 so I just add one of them to the Preprocessor Definitions

_WINSOCKAPI_ will gives some warning, something like "redefinition Macro definition"(?),those c code still can be compiled and run with wxWidgets

But WIN32_LEAN_AND_MEAN! this is magic!

add it and everythings fixed!

the AppendString() of my list just like printf() now :D

now it runs smoothly without any warning, like a 4K60FPS video game 8)
Last edited by DavidHart on Thu May 13, 2021 3:21 pm, edited 1 time in total.
Reason: Moderator: Removed more excessive punctuation.

Post Reply