diff --git a/examples/Makefile b/examples/Makefile
index 201b1abb..a4e301b5 100644
--- a/examples/Makefile
+++ b/examples/Makefile
@@ -3,7 +3,7 @@
# `wildcard ./*/` works in both linux and linux/wine, while `wildcard */` enumerates nothing under wine
SUBDIRS = $(sort $(dir $(wildcard ./*/)))
-SUBDIRS:=$(filter-out ./ ./CC3200/ ./ESP8266_RTOS/ ./MSP432/ ./NXP_LPC4088/ ./NXP_K64/ ./PIC32/ ./STM32F4_CC3100/ ./mbed/ ./nRF51/ ./nRF52/, $(SUBDIRS))
+SUBDIRS:=$(filter-out ./ ./CC3200/ ./ESP8266_RTOS/ ./MSP432/ ./NXP_LPC4088/ ./NXP_K64/ ./PIC32/ ./STM32F4_CC3100/ ./mbed/ ./nRF51/ ./nRF52/ ./WinCE/, $(SUBDIRS))
ifeq ($(OS), Windows_NT)
SUBDIRS:=$(filter-out ./netcat/ ./raspberry_pi_mjpeg_led/ ./captive_dns_server/, $(SUBDIRS))
diff --git a/examples/WinCE/http_server/http_server.cpp b/examples/WinCE/http_server/http_server.cpp
new file mode 100644
index 00000000..e3321b07
--- /dev/null
+++ b/examples/WinCE/http_server/http_server.cpp
@@ -0,0 +1,60 @@
+#include "stdafx.h"
+#include "mongoose.h"
+
+static const char *s_http_port = "8000";
+static struct mg_serve_http_opts s_http_server_opts;
+
+void ev_handler(struct mg_connection *nc, int ev, void *ev_data) {
+ switch (ev) {
+ case MG_EV_ACCEPT: {
+ char addr[32];
+ mg_sock_addr_to_str(&nc->sa, addr, sizeof(addr),
+ MG_SOCK_STRINGIFY_IP | MG_SOCK_STRINGIFY_PORT);
+ printf("%p: Connection from %s\r\n", nc, addr);
+ break;
+ }
+ case MG_EV_HTTP_REQUEST: {
+ struct http_message *hm = (struct http_message *) ev_data;
+ char addr[32];
+ mg_sock_addr_to_str(&nc->sa, addr, sizeof(addr),
+ MG_SOCK_STRINGIFY_IP | MG_SOCK_STRINGIFY_PORT);
+ printf("%p: %.*s %.*s\r\n", nc, (int) hm->method.len, hm->method.p,
+ (int) hm->uri.len, hm->uri.p);
+ mg_send_response_line(nc, 200,
+ "Content-Type: text/html\r\n"
+ "Connection: close");
+ mg_printf(nc,
+ "\r\n
Hello, %s!
\r\n"
+ "You asked for %.*s\r\n",
+ addr, (int) hm->uri.len, hm->uri.p);
+ nc->flags |= MG_F_SEND_AND_CLOSE;
+ break;
+ }
+ case MG_EV_CLOSE: {
+ printf("%p: Connection closed\r4\n", nc);
+ break;
+ }
+ }
+}
+
+int _tmain(int argc, _TCHAR* argv[]) {
+ struct mg_mgr mgr;
+ struct mg_connection *nc;
+
+ mg_mgr_init(&mgr, NULL);
+ printf("Starting web server on port %s\n", s_http_port);
+ nc = mg_bind(&mgr, s_http_port, ev_handler);
+ if (nc == NULL) {
+ printf("Failed to create listener\n");
+ return 1;
+ }
+
+ mg_set_protocol_http_websocket(nc);
+
+ for (;;) {
+ mg_mgr_poll(&mgr, 1000);
+ }
+ mg_mgr_free(&mgr);
+
+ return 0;
+}
diff --git a/examples/WinCE/http_server/http_server.vcproj b/examples/WinCE/http_server/http_server.vcproj
new file mode 100644
index 00000000..da664ad3
--- /dev/null
+++ b/examples/WinCE/http_server/http_server.vcproj
@@ -0,0 +1,269 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/examples/WinCE/http_server/stdafx.cpp b/examples/WinCE/http_server/stdafx.cpp
new file mode 100644
index 00000000..95887079
--- /dev/null
+++ b/examples/WinCE/http_server/stdafx.cpp
@@ -0,0 +1,8 @@
+// stdafx.cpp : source file that includes just the standard includes
+// http_server.pch will be the pre-compiled header
+// stdafx.obj will contain the pre-compiled type information
+
+#include "stdafx.h"
+
+// TODO: reference any additional headers you need in STDAFX.H
+// and not in this file
diff --git a/examples/WinCE/http_server/stdafx.h b/examples/WinCE/http_server/stdafx.h
new file mode 100644
index 00000000..2c3dc089
--- /dev/null
+++ b/examples/WinCE/http_server/stdafx.h
@@ -0,0 +1,56 @@
+// stdafx.h : include file for standard system include files,
+// or project specific include files that are used frequently, but
+// are changed infrequently
+//
+
+#pragma once
+
+#pragma comment(linker, "/nodefaultlib:libc.lib")
+#pragma comment(linker, "/nodefaultlib:libcd.lib")
+
+// NOTE - this value is not strongly correlated to the Windows CE OS version being targeted
+#define WINVER _WIN32_WCE
+
+#include
+#if defined(WIN32_PLATFORM_PSPC) || defined(WIN32_PLATFORM_WFSP)
+#define SHELL_AYGSHELL
+#endif
+
+#ifdef _CE_DCOM
+#define _ATL_APARTMENT_THREADED
+#endif
+
+#include
+
+#include
+#pragma comment(lib, "aygshell.lib")
+
+
+
+#include
+#include
+
+#if defined(WIN32_PLATFORM_PSPC) || defined(WIN32_PLATFORM_WFSP)
+#ifndef _DEVICE_RESOLUTION_AWARE
+#define _DEVICE_RESOLUTION_AWARE
+#endif
+#endif
+
+#ifdef _DEVICE_RESOLUTION_AWARE
+#include "DeviceResolutionAware.h"
+#endif
+
+#if _WIN32_WCE < 0x500 && ( defined(WIN32_PLATFORM_PSPC) || defined(WIN32_PLATFORM_WFSP) )
+ #pragma comment(lib, "ccrtrtti.lib")
+ #ifdef _X86_
+ #if defined(_DEBUG)
+ #pragma comment(lib, "libcmtx86d.lib")
+ #else
+ #pragma comment(lib, "libcmtx86.lib")
+ #endif
+ #endif
+#endif
+
+#include
+
+// TODO: reference additional headers your program requires here
diff --git a/mongoose.c b/mongoose.c
index d3cf32d0..aee9eddb 100644
--- a/mongoose.c
+++ b/mongoose.c
@@ -3070,7 +3070,7 @@ static sock_t mg_open_listening_socket(union socket_address *sa, int type,
if ((sock = socket(sa->sa.sa_family, type, proto)) != INVALID_SOCKET &&
#if !MG_LWIP /* LWIP doesn't support either */
-#if defined(_WIN32) && defined(SO_EXCLUSIVEADDRUSE)
+#if defined(_WIN32) && defined(SO_EXCLUSIVEADDRUSE) && !defined(WINCE)
/* "Using SO_REUSEADDR and SO_EXCLUSIVEADDRUSE" http://goo.gl/RmrFTm */
!setsockopt(sock, SOL_SOCKET, SO_EXCLUSIVEADDRUSE, (void *) &on,
sizeof(on)) &&
diff --git a/mongoose.h b/mongoose.h
index 780fa084..c1d7331d 100644
--- a/mongoose.h
+++ b/mongoose.h
@@ -1170,12 +1170,10 @@ typedef uint32_t in_addr_t;
#define CS_ENABLE_STDIO 1
#endif
-typedef unsigned int* uintptr_t;
#define abort() DebugBreak();
#ifndef BUFSIZ
#define BUFSIZ 4096
-#define ENOMEM ERROR_NOT_ENOUGH_MEMORY
#endif
/*
* Explicitly disabling MG_ENABLE_THREADS for WinCE
@@ -1199,8 +1197,26 @@ typedef struct _stati64 {
uint32_t st_mode;
} cs_stat_t;
+/*
+ * WinCE 6.0 has a lot of useful definitions in ATL (not windows.h) headers
+ * use #ifdefs to avoid conflicts
+ */
+
+#ifndef ENOENT
#define ENOENT ERROR_PATH_NOT_FOUND
+#endif
+
+#ifndef EACCES
#define EACCES ERROR_ACCESS_DENIED
+#endif
+
+#ifndef ENOMEM
+#define ENOMEM ERROR_NOT_ENOUGH_MEMORY
+#endif
+
+#ifndef _UINTPTR_T_DEFINED
+typedef unsigned int* uintptr_t;
+#endif
#define _S_IFREG 2
#define _S_IFDIR 4