Index: trunk/include/regfi.h
===================================================================
--- trunk/include/regfi.h	(revision 225)
+++ trunk/include/regfi.h	(revision 226)
@@ -84,7 +84,13 @@
 #undef _EXPORT
 #endif
+#ifdef REGFI_WIN32
+#define _EXPORT __declspec(dllexport)
+#else
 #define _EXPORT __attribute__((visibility("default")))
-
-
+#endif
+
+#ifndef EOVERFLOW
+# define EOVERFLOW E2BIG
+#endif
 
 /******************************************************************************/
@@ -709,5 +715,5 @@
 typedef struct _regfi_raw_file
 {
-  off_t    (* seek)(); /* (REGFI_RAW_FILE* self, off_t offset, int whence) */
+  int64_t  (* seek)(); /* (REGFI_RAW_FILE* self, uint64_t offset, int whence) */
   ssize_t  (* read)(); /* (REGFI_RAW_FILE* self, void* buf, size_t count) */
 
@@ -1627,11 +1633,11 @@
 /*    Private (and undocumented) Functions                                    */
 /******************************************************************************/
-off_t                 regfi_raw_seek(REGFI_RAW_FILE* self, 
-				     off_t offset, int whence);
+int64_t               regfi_raw_seek(REGFI_RAW_FILE* self, 
+				     uint64_t offset, int whence);
 ssize_t               regfi_raw_read(REGFI_RAW_FILE* self, 
 				     void* buf, size_t count);
 _EXPORT
-off_t                 regfi_seek(REGFI_RAW_FILE* file_cb, 
-				 off_t offset, int whence);
+uint64_t              regfi_seek(REGFI_RAW_FILE* file_cb, 
+				 uint64_t offset, int whence);
 _EXPORT
 uint32_t              regfi_read(REGFI_RAW_FILE* file_cb, 
Index: trunk/lib/regfi.c
===================================================================
--- trunk/lib/regfi.c	(revision 225)
+++ trunk/lib/regfi.c	(revision 226)
@@ -573,6 +573,11 @@
 
 
-off_t regfi_raw_seek(REGFI_RAW_FILE* self, off_t offset, int whence)
-{
+int64_t regfi_raw_seek(REGFI_RAW_FILE* self, uint64_t offset, int whence)
+{
+  if(sizeof(off_t) == 4 && offset > 2147483647)
+  {
+    errno = EOVERFLOW;
+    return -1;
+  }
   return lseek(*(int*)self->state, offset, whence);
 }
@@ -587,5 +592,5 @@
  * Convenience function to wrap up the ugly callback stuff
  *****************************************************************************/
-off_t regfi_seek(REGFI_RAW_FILE* file_cb, off_t offset, int whence)
+uint64_t regfi_seek(REGFI_RAW_FILE* file_cb, uint64_t offset, int whence)
 {
   return file_cb->seek(file_cb, offset, whence);
@@ -1561,5 +1566,5 @@
   REGFI_HBIN* hbin = NULL;
   uint32_t hbin_off, cache_secret;
-  int32_t file_length;
+  int64_t file_length;
   bool rla;
 
@@ -1567,5 +1572,5 @@
    * and one hbin.
    */
-  file_length = file_cb->seek(file_cb, 0, SEEK_END);
+  file_length = regfi_seek(file_cb, 0, SEEK_END);
   if(file_length < REGFI_REGF_SIZE+REGFI_HBIN_ALLOC)
   {
@@ -1574,5 +1579,5 @@
     return NULL;
   }
-  file_cb->seek(file_cb, 0, SEEK_SET);
+  regfi_seek(file_cb, 0, SEEK_SET);
 
   if(output_encoding != REGFI_ENCODING_UTF8
Index: trunk/python/pyregfi/__init__.py
===================================================================
--- trunk/python/pyregfi/__init__.py	(revision 225)
+++ trunk/python/pyregfi/__init__.py	(revision 226)
@@ -177,5 +177,5 @@
 def GetLogMessages():
     msgs = regfi.regfi_log_get_str()
-    if msgs == None:
+    if not msgs:
         return ''
     return msgs.decode('utf-8')
@@ -625,23 +625,33 @@
     # @note Supplied file must be seekable
     def __init__(self, fh):
+        # The fileno method may not exist, or it may throw an exception
+        # when called if the file isn't backed with a descriptor.
+        fn = None
         try:
-            # The fileno method may not exist, or it may throw an exception
-            # when called if the file isn't backed with a descriptor.
-            if hasattr(fh, 'fileno'):
-                self.file = regfi.regfi_alloc(fh.fileno(), REGFI_ENCODING_UTF8)
-                return
+            # XXX: Native calls to Windows filenos don't seem to work.  
+            #      Need to investigate why.
+            if not is_win32 and hasattr(fh, 'fileno'):
+                fn = fh.fileno()
         except:
             pass
-        
-        fh.seek(0)
-        self.raw_file = structures.REGFI_RAW_FILE()
-        self.raw_file.fh = fh
-        self.raw_file.seek = seek_cb_type(self.raw_file.cb_seek)
-        self.raw_file.read = read_cb_type(self.raw_file.cb_read)
-        self.file = regfi.regfi_alloc_cb(pointer(self.raw_file), REGFI_ENCODING_UTF8)
-        if not self.file:
-            # XXX: switch to non-generic exception
-            raise Exception("Could not open registry file.  Current log:\n"
-                            + GetLogMessages())
+
+        if fn != None:
+            self.file = regfi.regfi_alloc(fn, REGFI_ENCODING_UTF8)
+            if not self.file:
+                # XXX: switch to non-generic exception
+                raise Exception("Could not open registry file.  Current log:\n"
+                                + GetLogMessages())
+        else:
+            fh.seek(0)
+            self.raw_file = structures.REGFI_RAW_FILE()
+            self.raw_file.fh = fh
+            self.raw_file.seek = seek_cb_type(self.raw_file.cb_seek)
+            self.raw_file.read = read_cb_type(self.raw_file.cb_read)
+            self.file = regfi.regfi_alloc_cb(pointer(self.raw_file), REGFI_ENCODING_UTF8)
+            if not self.file:
+                # XXX: switch to non-generic exception
+                raise Exception("Could not open registry file.  Current log:\n"
+                                + GetLogMessages())
+
 
     def __getattr__(self, name):
@@ -703,5 +713,5 @@
     def __init__(self, hive):
         self._iter = regfi.regfi_iterator_new(hive.file, REGFI_ENCODING_UTF8)
-        if self._iter == None:
+        if not self._iter:
             raise Exception("Could not create iterator.  Current log:\n"
                             + GetLogMessages())
Index: trunk/python/pyregfi/structures.py
===================================================================
--- trunk/python/pyregfi/structures.py	(revision 225)
+++ trunk/python/pyregfi/structures.py	(revision 226)
@@ -13,4 +13,5 @@
 from ctypes import *
 
+is_win32 = hasattr(ctypes, 'windll')
 
 # XXX: can we always be sure enums are this size?
@@ -61,6 +62,5 @@
         except Exception:
             traceback.print_exc()
-            # XXX: os.EX_IOERR may not be available on Windoze
-            set_errno(os.EX_IOERR)
+            set_errno(74) # os.EX_IOERR
             return -1
 
@@ -76,6 +76,5 @@
         except Exception:
             traceback.print_exc()
-            # XXX: os.EX_IOERR may not be available on Windoze
-            set_errno(os.EX_IOERR)
+            set_errno(74) # os.EX_IOERR
             return -1
         return len(tmp)
@@ -84,19 +83,18 @@
 # Load libregfi according to platform
 regfi = None
-if hasattr(ctypes, 'windll'):
+if is_win32:
+    # XXX: Using C calling conventions on cross-compiled DLLs seems to work fine
+    #      on Windows, but I'm not sure if stdcall symbols are supported 
+    #      correctly for native Windows binaries...
     #regfi = ctypes.windll.libregfi
-    regfi = ctypes.WinDLL('libregfi.dll', use_errno=True)
-    CB_FACTORY = ctypes.WINFUNCTYPE
+    #CB_FACTORY = ctypes.WINFUNCTYPE
+    regfi = ctypes.CDLL('libregfi.dll', use_errno=True)
+    CB_FACTORY = ctypes.CFUNCTYPE
 else:
     regfi = ctypes.CDLL(ctypes.util.find_library('regfi'), use_errno=True)
     CB_FACTORY = ctypes.CFUNCTYPE
 
-# XXX: how can we know for sure the size of off_t?  
-#      -D_FILE_OFFSET_BITS=64 might help, need to research this
-#      Also, may need to use something like ctypes_configure
-#seek_cb_type = CB_FACTORY(c_int64, POINTER(REGFI_RAW_FILE), c_uint64, c_int, use_errno=True)
-seek_cb_type = CB_FACTORY(c_int64, POINTER(REGFI_RAW_FILE), c_uint64, c_int)
-#read_cb_type = CB_FACTORY(c_int64, POINTER(REGFI_RAW_FILE), POINTER(c_char), c_size_t, use_errno=True)
-read_cb_type = CB_FACTORY(c_int64, POINTER(REGFI_RAW_FILE), POINTER(c_char), c_size_t)
+seek_cb_type = CB_FACTORY(c_int64, POINTER(REGFI_RAW_FILE), c_uint64, c_int, use_errno=True)
+read_cb_type = CB_FACTORY(c_int64, POINTER(REGFI_RAW_FILE), POINTER(c_char), c_size_t, use_errno=True)
 
 
