Problems with winsock2 functions in a big JUCEy project


I have inherited a JUCE project and am trying to merge some new functionality into which uses a UDP socket. That code is all written and I’d prefer leave it as is. The trouble is, it uses a bunch of winsock/2.h functions like ntohl, recvfrom, etc. and there seems to be a conflict in the JUCE project somewhere because if I include winsock2.h I get winnt.h errors, a la:
1>d:\microsoft sdks\windows\v7.0a\include\winnt.h(1084): error C2988: unrecognizable template declaration/definition

if I don’t include winsock then it doesn’t know what ntohl(), etc. are.

I am aware of the JUCE datagrams code, this would require rewriting a chunk of code which is working outside of this JUCE project.

FWIW, I am in Visual Studio Express 2010.


hmmm, well I have a working option but…

if I add #include<WinSock2.h> to the top of JuceHeader.h then everyone is happy but surely there is a more robust solution.

I suspect this would be a good time to use an ifndef or perhaps some linker options but for now I’m moving forward with this hack.


The “unrecognisable template” thing sounds like it’s because you’re including winsock.h after juce.h, and juce defines a “T” macro which messes up some windows header code. Either “#undef T” or include your headers in the other order and it’ll be fine.

(I’m going to deprecate that damned T macro in the near future, it was a stupid idea, and has always been a PITA!)