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
need help!!! can not use some basic socket code!! Topic is solved
need help!!! can not use some basic socket code!!
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!!!!!!!!!!
Reason: Moderator: Removed multiple exclamation marks etc e.g. !!!!!!!!!!a lot of error!!!!!!!!!!a lot of error!!!!!!!!!!
Re: need help!!! can not use some basic socket code!!
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!
Re: need help!!! can not use some basic socket code!!
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.
I do not think you can mix two WinSock version in one application but I may be wrong.
-
- Super wx Problem Solver
- Posts: 466
- Joined: Tue Jun 20, 2006 6:47 pm
- Contact:
Re: need help!!! can not use some basic socket code!!
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.
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.
Re: need help!!! can not use some basic socket code!!
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
now it runs smoothly without any warning, like a 4K60FPS video game
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
now it runs smoothly without any warning, like a 4K60FPS video game
Last edited by DavidHart on Thu May 13, 2021 3:21 pm, edited 1 time in total.
Reason: Moderator: Removed more excessive punctuation.
Reason: Moderator: Removed more excessive punctuation.