Fix build issues with Visual C++ (implemented macro version of snprintf + re-ordered headers to ensure that winsock is included ahead of windows.h)


git-svn-id: svn://svn.code.sf.net/p/tigervnc/code/trunk@4527 3789f03b-4d11-0410-bbf8-ca57d06f2519
diff --git a/vncviewer/CConn.cxx b/vncviewer/CConn.cxx
index 5ae26f0..8d233f0 100644
--- a/vncviewer/CConn.cxx
+++ b/vncviewer/CConn.cxx
@@ -18,7 +18,9 @@
  */
 
 #include <assert.h>
+#ifndef _WIN32
 #include <unistd.h>
+#endif
 
 #include <rfb/CMsgWriter.h>
 #include <rfb/encodings.h>
@@ -37,6 +39,10 @@
 #include "i18n.h"
 #include "parameters.h"
 
+#ifdef WIN32
+#include "win32.h"
+#endif
+
 using namespace rdr;
 using namespace rfb;
 using namespace std;
diff --git a/vncviewer/DesktopWindow.cxx b/vncviewer/DesktopWindow.cxx
index 456e372..859d2b6 100644
--- a/vncviewer/DesktopWindow.cxx
+++ b/vncviewer/DesktopWindow.cxx
@@ -21,9 +21,6 @@
 #include <stdio.h>
 #include <string.h>
 
-#include <FL/Fl_Scroll.H>
-#include <FL/x.H>
-
 #include <rfb/LogWriter.h>
 
 #include "DesktopWindow.h"
@@ -31,6 +28,9 @@
 #include "i18n.h"
 #include "parameters.h"
 
+#include <FL/Fl_Scroll.H>
+#include <FL/x.H>
+
 #ifdef WIN32
 #include "win32.h"
 #endif
diff --git a/vncviewer/DesktopWindow.h b/vncviewer/DesktopWindow.h
index 0848306..a190b70 100644
--- a/vncviewer/DesktopWindow.h
+++ b/vncviewer/DesktopWindow.h
@@ -22,13 +22,13 @@
 
 #include <map>
 
-#include <FL/Fl.H>
-#include <FL/Fl_Window.H>
-
 #include <rfb/Rect.h>
 
 #include "Viewport.h"
 
+#include <FL/Fl.H>
+#include <FL/Fl_Window.H>
+
 class CConn;
 
 class DesktopWindow : public Fl_Window {
diff --git a/vncviewer/OptionsDialog.cxx b/vncviewer/OptionsDialog.cxx
index abe6a89..d3928b5 100644
--- a/vncviewer/OptionsDialog.cxx
+++ b/vncviewer/OptionsDialog.cxx
@@ -20,10 +20,6 @@
 
 #include <list>
 
-#include <FL/Fl_Tabs.H>
-#include <FL/Fl_Button.H>
-#include <FL/Fl_Return_Button.H>
-
 #include <rdr/types.h>
 #include <rfb/encodings.h>
 
@@ -38,6 +34,10 @@
 #include "i18n.h"
 #include "parameters.h"
 
+#include <FL/Fl_Tabs.H>
+#include <FL/Fl_Button.H>
+#include <FL/Fl_Return_Button.H>
+
 using namespace std;
 using namespace rdr;
 using namespace rfb;
diff --git a/vncviewer/Viewport.cxx b/vncviewer/Viewport.cxx
index 8d57e9b..80b4854 100644
--- a/vncviewer/Viewport.cxx
+++ b/vncviewer/Viewport.cxx
@@ -21,9 +21,6 @@
 #include <stdio.h>
 #include <string.h>
 
-#include <FL/fl_draw.H>
-#include <FL/fl_ask.H>
-
 #include <rfb/CMsgWriter.h>
 #include <rfb/LogWriter.h>
 
@@ -46,6 +43,13 @@
 #include "parameters.h"
 #include "keysym2ucs.h"
 
+#include <FL/fl_draw.H>
+#include <FL/fl_ask.H>
+
+#ifdef WIN32
+#include "win32.h"
+#endif
+
 using namespace rfb;
 using namespace rdr;
 
diff --git a/vncviewer/vncviewer.cxx b/vncviewer/vncviewer.cxx
index b9e8ab5..41d3796 100644
--- a/vncviewer/vncviewer.cxx
+++ b/vncviewer/vncviewer.cxx
@@ -1,6 +1,6 @@
 /* Copyright (C) 2002-2005 RealVNC Ltd.  All Rights Reserved.
  * Copyright 2011 Pierre Ossman <ossman@cendio.se> for Cendio AB
- * Copyright (C) 2011 D. R. Commander
+ * Copyright (C) 2011 D. R. Commander.  All Rights Reserved.
  * 
  * This is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -53,6 +53,10 @@
 #include "ServerDialog.h"
 #include "UserDialog.h"
 
+#ifdef WIN32
+#include "win32.h"
+#endif
+
 rfb::LogWriter vlog("main");
 
 using namespace network;
diff --git a/vncviewer/win32.h b/vncviewer/win32.h
index 0cc1c11..35be77b 100644
--- a/vncviewer/win32.h
+++ b/vncviewer/win32.h
@@ -1,5 +1,6 @@
 /* Copyright (C) 2002-2005 RealVNC Ltd.  All Rights Reserved.
  * Copyright 2011 Pierre Ossman <ossman@cendio.se> for Cendio AB
+ * Copyright (C) 2011 D. R. Commander.  All Rights Reserved.
  * 
  * This is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -20,6 +21,10 @@
 #ifndef __VNCVIEWER_WIN32_H__
 #define __VNCVIEWER_WIN32_H__
 
+#ifdef _MSC_VER
+#define snprintf(str, n, format, ...) _snprintf_s(str, n, _TRUNCATE, format, __VA_ARGS__)
+#endif
+
 extern "C" {
 
 int win32_enable_lowlevel_keyboard(HWND hwnd);