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)
 
 
