Pages: [1]   Go Down
Author Topic: Arduino SerialClass / Windows TCP/IP Socket Clash  (Read 1005 times)
0 Members and 1 Guest are viewing this topic.
Bristol, UK
Offline Offline
Newbie
*
Karma: 0
Posts: 15
Robots are cool
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Hey Guys,

This may not be the most appropriate place to ask this question as it relates more to C++ than Arduino, but I thought someone else may have already solved this problem.

I've just used the SerialClass posted in the Arduino Playground (http://arduino.cc/playground/Interfacing/CPPWindows) to interface the serial output of an Arduino with a C++ console application via Microsoft Visual Studio. That works great and I can see the data from the attached sensor in the console.

I'm now trying to integrate that functionality with windows TCP/IP sockets, so that I can broadcast the sensor data to a server program. I've been using code to do that which uses the following headers to enable the socket functionality.

#include <Afxwin.h>
#include <winsock2.h>

The problem is that including these headers messes up the SerialClass, as it #includes windows.h. I get the following error:
fatal error C1189: #error :  WINDOWS.H already included.  MFC apps must not #include <windows.h>.

If I remove windows.h then I get a 81 errors just from the SerialClass (as expected), such as missing ';'s, when they clearly exist.

I tried moving the use of MFC to standard windows libraries and including #define _AFXDLL as prompted but that gives me the same error as above.

So the Arduino SerialClass needs windows.h, and sockets need winsock2.h, which can't be used in conjuction with windows.h

Any ideas how to get around this? Any help appreciated. As you can tell, I'm not too hot on C++!

Thanks,

Ad
Logged

Bristol, UK
Offline Offline
Newbie
*
Karma: 0
Posts: 15
Robots are cool
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Okay, so someone on CodeProject helped me figure it out. I'm putting the solution up here incase anyone else has the same problem.
You need to use precompiled headers with "stdafx.h", this already contains "afxwin.h". Also you need "ws2_32.lib" in the Linker->Additional dependancies.

Here's a link to the full discussion: http://www.codeproject.com/Messages/4200841/Serial-Port-Windows-Sockets-clash.aspx
Logged

Pages: [1]   Go Up
Jump to: