Click here to Skip to main content
15,884,176 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I have written a Win32 console app in visual studio 2003 .net which uses sockets therefore includes winsock2.h and the wsock32.lib.

I now have to incorporate some files that someone else has written and also include a .lib and some headers in my project's setting in order for their code to work. The headers for their code that I have added to stdafx.h are called ModuleIo.h and ApplicatioIo.h. These headers include a lot of other headers that are in the directory that I have added to the include directories in the project settings. But none of these includes are windows headers - they are all provided by someone and have more of their code in.

The trouble is I now get the "C1189 windows.h already defined" problem. I have read so much about this on the internet but I still can't find a solution to my problem. I will post my stdafx.h here, but the problem does not occur until I incorporate somebody elses code and .libs. Everyone else seems to solve this by reordering their #includes in stdafx.h but I have tried that (putting winsock2.h at the start or end) but it makes no difference.

// stdafx.h : 
#pragma once
#include <winsock2.h>
#include <stdio.h>
#include <tchar.h>
#include <process.h> //for _beginThread
#include <iostream>
#include <stdlib.h>
#include <conio.h> //for getche()
#include <errno.h>
#include <time.h>
#include <string>
#include <sstream>
#include <stddef.h>
#include <atlbase.h> //for debug TRACE
#include <signal.h>
#include "DigiConfig.h"
#include "CardStatus.h"//for the enums E_RAD2_STATES
#include "CardBulkXfer.h"
#include "SharedMemory.h"
#include "CardInterface.h"
#include "ModuleIo.h"// this is an added header
#include "ApplicationIo.h"// this is an added header
#include "CardCtrl.h"
#include "CardThread.h"
#include "ClientHandlerThread.h"
#include "ConsoleHandler.h"
#include "CardDataWriterThread.h"
#include "CardDataHandlerThread.h"


I did try putting #undef _WINDOWS_ after the #include "winsock2.h", which remove dthe error but produced a new one about an amiguous call to Sleep - which is defined in winbase.h and atlbase.h, so I am still including two defintions of methods which i shouldn't be and I really don't know what to try next. Please help!
Posted
Updated 18-Apr-12 23:28pm
v3

Winsock2.h includes Windows.h if not included so far. But it is always better to have Windows.h included before.

The best way is to let Visual Studio generate a stdafx.h file upon project creation. Then it will also include winsock2.h when checking the socket options of the project.

You may create a new project with these settings and then add all your existing files to the new project.

As an alternative, you may add the windows.h file and other required windows header files on top of your stdafx.h file.
 
Share this answer
 
Comments
Jackie Lloyd 19-Apr-12 7:03am    
Thanks, I did in the end solve it by putting the winsock include at the end of the includes in stdafx.h. I thought I had tried that before but I have had a lot of errors to solve so was probably a bit confused as to what was fixing what. Its a bit clearer now, and I will try your method when I next create a new project like this. Many thanks :)
error C1180 will occur when you include windows.h before afxwin.h. , i don't know this case happens in your program.

jkchan
http://cgmath.blogspot.com[^]
 
Share this answer
 
Comments
Marius Bancila 19-Apr-12 6:13am    
afxwin.h is an MFC header. he has a Win32 console app and didn't say anything about MFC support.
Jackie Lloyd 19-Apr-12 7:05am    
I am not using mfc but i don't know if the .lib or headers I had to include are referencing it. Anyhow, it is solved as above. Thankyou very much for your help

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900