#define TRUE  1
 #define FALSE 0
 
-#ifndef MAX
-#define MAX(a, b) ((a) > (b) ? (a) : (b))
-#endif
-#ifndef MIN
-#define MIN(a, b) ((a) < (b) ? (a) : (b))
-#endif
-
 #ifdef HAVE_TLS
 #define have_tls 1
 #else
 
    CF_CREATED                         /* file created, no data to extract */
 };
 
+#ifndef MAX
+#define MAX(a, b) ((a) > (b) ? (a) : (b))
+#endif
+#ifndef MIN
+#define MIN(a, b) ((a) < (b) ? (a) : (b))
+#endif
 
 #endif /* __bc_types_INCLUDED */
 
 }
 
 int
-fstat(int fd, struct stat *sb)
+fstat(intptr_t fd, struct stat *sb)
 {
    BY_HANDLE_FILE_INFORMATION info;
 
       return -1;
    }
 
-   rval = fstat((int)h, sb);
+   rval = fstat((intprt_t)h, sb);
    CloseHandle(h);
 
    if (attr & FILE_ATTRIBUTE_DIRECTORY &&
                                      // process terminates we can
                                      // detect eof.
         // ugly but convert WIN32 HANDLE to FILE*
-        int rfd = _open_osfhandle((long)hChildStdoutRdDup, O_RDONLY | O_BINARY);
+        int rfd = _open_osfhandle((intptr_t)hChildStdoutRdDup, O_RDONLY | O_BINARY);
         if (rfd >= 0) {
            bpipe->rfd = _fdopen(rfd, "rb");
         }
         CloseHandle(hChildStdinRd); // close our read side so as not
                                     // to interfre with child's copy
         // ugly but convert WIN32 HANDLE to FILE*
-        int wfd = _open_osfhandle((long)hChildStdinWrDup, O_WRONLY | O_BINARY);
+        int wfd = _open_osfhandle((intptr_t)hChildStdinWrDup, O_WRONLY | O_BINARY);
         if (wfd >= 0) {
            bpipe->wfd = _fdopen(wfd, "wb");
         }
     return result;
 }
 
+#ifndef MINGW64
 int
 utime(const char *fname, struct utimbuf *times)
 {
     }
     return rval;
 }
+#endif
 
 #if 0
 int
 
 
 #include <malloc.h>
 
+#ifdef MINGW64
+#include <direct.h>
+#define _declspec __declspec
+#endif
+
+#ifdef _WIN64
+# define GWL_USERDATA  GWLP_USERDATA
+#endif
+
 #ifndef INT64
 #define INT64 long long int
 #endif
 ssize_t win32_write(int fd, const void *buffer, size_t count);
 int win32_ioctl(int fd, unsigned long int req, ...);
 
+#ifndef MINGW64
 #define open   _open
+#endif
 
 int fcntl(int fd, int cmd, long arg);
-int fstat(int fd, struct stat *sb);
+int fstat(intptr_t fd, struct stat *sb);
 
 int inet_aton(const char *cp, struct in_addr *inp);
 int kill(int pid, int signo);
 
         io->status = 0;
         io->io_errno = 0;
 
-        io->status = min(io->count, (int)(buffer_size - buffer_pos));
+        io->status = MIN(io->count, (int)(buffer_size - buffer_pos));
         if (io->status == 0)
                 return bRC_OK;
         memcpy(io->buf, buffer + buffer_pos, io->status);
 
 const int VSSClient::GetWriterState(int nIndex)
 {
    alist* pV = (alist*)m_pAlistWriterState;   
-   return (int)pV->get(nIndex);
+   return (intptr_t)pV->get(nIndex);
 }
 
 void VSSClient::AppendWriterInfo(int nState, const char* pszInfo)
 
 #include <pthread.h>
 
 #undef  _WIN32_IE
-#define _WIN32_IE 0x0401
+#ifdef MINGW64
+# define _WIN32_IE 0x0501
+#else
+# define _WIN32_IE 0x0401
+#endif  // MINGW64
 #undef  _WIN32_WINNT
 #define _WIN32_WINNT 0x0501
 #include <commctrl.h>
 
 
 
 General:
+23Mar09
+ebl  Tweak code to compile win64 version with mingw
 21Mar09
 Kes  Attempt to correct timing problems with starting bat and obtaining
      lists. Maintain in_command counter to know when a list is coming.