If a project using socket functions and a little bit more is to be compiled for Windows 7, I get errors.
Apparently the type (structure) NDIS_OBJECT_HEADER is declared later as the first use. In order to compile the project, there is a work around (for me), but this is not the correct way:
#ifdef __POCC__
#define _NETIOAPI_H
#endif
The following code allows to reproduce the problem:
------------------------------------------------------------
// file bug.c
#define _WIN32_WINNT 0x0601
#include <stdio.h>
#include <stdlib.h>
//#include <windows.h> // Error
// PellesC\Include\Win\windot11.h(24): error #2078: Invalid struct field declarations.
// PellesC\Include\Win\windot11.h(24): error #2001: Syntax error: expected '}' but found 'NDIS_OBJECT_HEADER'.
#include <winsock2.h>
#include <ws2tcpip.h>
#include <iphlpapi.h> // Error as for windows.h
int __cdecl main(void)
{
printf("Hello\n");
return 0;
}
-----------------------------------------------------------
The hand made Makefile look as follows:
----------------------------------------------------------
INCLUDE = -I"$(PellesCDir)\Include\Win" -I"$(PellesCDir)\Include"
LIB = /LIBPATH:"$(PellesCDir)\Lib\Win" /LIBPATH:"$(PellesCDir)\Lib"
CFLAGS = /std:C99 -Tx86-coff /Ot /Ob1 /fp:precise /W1 /Gz /Ze $(INCLUDE)
LDFLAGS = /subsystem:console /machine:x86 $(LIB) kernel32.lib user32.lib wsock32.lib ws2_32.lib iphlpapi.lib
ASFLAGS = -AIA32 -Gz
LINK=polink
CC=pocc
bug.exe: bug.obj
$(LINK) $(LDFLAGS) /out:bug.exe bug.obj
bug.obj: bug.c
$(CC) $(CFLAGS) bug.c /Fo bug.obj
clean:
del bug.obj bug.exe
----------------------------------------------------------
Always place <winsock2.h> above <windows.h> and generally you should include windows headers before library headers ... a lesson I learned the hard way.
Try it like this and see if that helps...
#define WIN32_DEFAULT_LIBS // Pelles C specific, see appendix to help file
#include <winsock2.h>
#include <windows.h>
#include <ws2tcpip.h>
#include <iphlpapi.h>
#include <stdio.h>
#include <stdlib.h>
(fwiw ... it's like this in vc++ as well ... winsock before windows)
Quote from: CommonTater on September 27, 2012, 06:04:20 PM
Always place <winsock2.h> above <windows.h> and generally you should include windows headers before library headers ... a lesson I learned the hard way.
winsock2.h includes windows.h if it isn't included...
The position of windows.h or it ommission is not important.
The problem is that the structure I mentionned is declared after the first uses.
Quote from: jjsa on September 27, 2012, 08:33:16 PM
The position of windows.h or it ommission is not important.
The problem is that the structure I mentionned is declared after the first uses.
Yeah it does matter... however that doesn't seem to be what's causing this particular problem...
Strange...
Maybe there is a error in ntddndis.h at line 1000
Move that code to lower near end.
#if ((NTDDI_VERSION >= NTDDI_VISTA) || NDIS_SUPPORT_NDIS6)
#ifndef _WINDOT11_H
#include <windot11.h>
#endif
#endif /* NTDDI_VERSION >= NTDDI_VISTA */
Quote from: timovjl on September 27, 2012, 08:57:34 PM
Maybe there is a error in ntddndis.h at line 1000
Move that code to lower near end.
#if ((NTDDI_VERSION >= NTDDI_VISTA) || NDIS_SUPPORT_NDIS6)
#ifndef _WINDOT11_H
#include <windot11.h>
#endif
#endif /* NTDDI_VERSION >= NTDDI_VISTA */
or perhaps
#define NTDDI_VERSION NTDDI_VISTA
at the top of his source page
The file has to be corrected for all peles C user, for my project I have a work around and I expect that the delivered header files are correct. my posting is only a bug report.