Index: /SConstruct
===================================================================
--- /SConstruct	(revision 224)
+++ /SConstruct	(revision 225)
@@ -33,6 +33,10 @@
 
 win32_cmds='''
-rm -rf .release && mkdir -p .release/%s
+rm -rf .release && mkdir -p .release/%s/python/pyregfi
 cp %s/src/*.exe .release/%s
+
+cp %s/pyregfi-distutils.py .release/%s/setup.py
+cp %s/python/pyregfi/*.py .release/%s/python/pyregfi
+
 cp win32/libiconv/bin/*.dll win32/libpthreads/bin/*.dll win32/libtalloc/bin/*.dll trunk/lib/*.dll .release/%s
 cd .release && zip -r %s.zip %s
@@ -113,5 +117,6 @@
                                             [input_prefix+'src/reglookup-recover.c']+extra_obj)
 
-            ret_val += win32_cmds % (t_base,input_prefix,
+            ret_val += win32_cmds % (t_base,input_prefix,t_base,input_prefix,
+                                     t_base,input_prefix,
                                      t_base,t_base,t_base,t_base,t_base)
 
Index: /test/pyregfi-smoketest.py
===================================================================
--- /test/pyregfi-smoketest.py	(revision 224)
+++ /test/pyregfi-smoketest.py	(revision 225)
@@ -3,6 +3,8 @@
 import sys
 import gc
+import io
 import time
 import pyregfi
+
 
 def usage():
@@ -15,5 +17,5 @@
 # Gathers various (meaningless) statistics to exercise simple attribute access
 # and to hopefully smoke out any bugs that can be identified by changing stats
-def iterTallyNames(hive):
+def iterTallyNames(hive, fh):
     key_count = 0
     key_lens = 0
@@ -60,5 +62,5 @@
 # to find the same key again, verifying it is the same.  This test is currently
 # very slow because no key caching is used.
-def iterParentWalk(hive):
+def iterParentWalk(hive, fh):
     i = 1
     for k in hive:
@@ -77,5 +79,5 @@
 # Uses the HiveIterator to walk all keys
 # Gathers various (meaningless) statistics about data/data_raw attributes
-def iterTallyData(hive):
+def iterTallyData(hive, fh):
     data_stat = 0.0
     dataraw_stat = 0.0
@@ -127,5 +129,5 @@
 # list dictionary access.  Also builds nonsensical statistics as an excuse
 # to access various base structure attributes.
-def recurseKeyTally(hive):
+def recurseKeyTally(hive, fh):
     checkValues(hive.root)
     recurseTree(hive.root, checkValues)
@@ -135,5 +137,5 @@
 
 # Iterates hive gathering stats about security and classname records
-def iterFetchRelated(hive):
+def iterFetchRelated(hive, fh):
     security_stat = 0.0
     classname_stat = 0.0
@@ -157,5 +159,5 @@
 
 
-def iterIterWalk(hive):
+def iterIterWalk(hive, fh):
     sk_stat = 0.0
     v_stat = 0.0
@@ -183,5 +185,12 @@
 
 
-
+def iterCallbackIO(hive, fh):
+    fh.seek(0)
+    new_fh = io.BytesIO(fh.read())
+    new_hive = pyregfi.Hive(new_fh)
+    for k in new_hive:
+        pass
+
+    
 if len(sys.argv) < 2:
     usage()
@@ -196,5 +205,5 @@
          ("iterIterWalk",iterIterWalk),]
 
-tests = [("iterIterWalk",iterIterWalk),]
+tests = [("iterCallbackIO",iterCallbackIO),]
 
 
@@ -211,5 +220,5 @@
         tstr = "'%s' on '%s'" % (tname,hname)
         print("##BEGIN %s:" % tstr)
-        t(hive)
+        t(hive, fh)
         print("##END %s; runtime=%f; messages:" % (tstr, time.time() - teststart))
         print(pyregfi.GetLogMessages())
Index: /trunk/SConstruct
===================================================================
--- /trunk/SConstruct	(revision 224)
+++ /trunk/SConstruct	(revision 225)
@@ -1,9 +1,7 @@
 import sys
 import os
-#import distutils.sysconfig
 
-#cflags = '-std=gnu99 -pedantic -Wall'
-cflags = '-std=gnu99 -pedantic -Wall -fvisibility=hidden -ggdb'
-
+cflags = '-std=gnu99 -pedantic -Wall -D_FILE_OFFSET_BITS=64 -fvisibility=hidden'
+cflags += ' -ggdb'
 
 lib_src = ['lib/regfi.c',
Index: /trunk/lib/regfi.c
===================================================================
--- /trunk/lib/regfi.c	(revision 224)
+++ /trunk/lib/regfi.c	(revision 225)
@@ -612,5 +612,7 @@
   do
   {
-    rret = file_cb->read(file_cb, buf + rsize, *length - rsize);
+    rret = file_cb->read(file_cb, 
+                         buf + rsize, 
+                         *length - rsize);
     if(rret > 0)
       rsize += rret;
Index: /trunk/python/pyregfi/__init__.py
===================================================================
--- /trunk/python/pyregfi/__init__.py	(revision 224)
+++ /trunk/python/pyregfi/__init__.py	(revision 225)
@@ -95,5 +95,4 @@
 import sys
 import time
-import weakref
 from pyregfi.structures import *
 
@@ -635,10 +634,14 @@
             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(self.raw_file, REGFI_ENCODING_UTF8)
-
+        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):
Index: /trunk/python/pyregfi/structures.py
===================================================================
--- /trunk/python/pyregfi/structures.py	(revision 224)
+++ /trunk/python/pyregfi/structures.py	(revision 225)
@@ -82,7 +82,21 @@
 
 
-# XXX: how can we know for sure the size of off_t and size_t?
-seek_cb_type = CFUNCTYPE(c_int64, POINTER(REGFI_RAW_FILE), c_uint64, c_int, use_errno=True)
-read_cb_type = CFUNCTYPE(c_int64, POINTER(REGFI_RAW_FILE), POINTER(c_char), c_uint64, use_errno=True)
+# Load libregfi according to platform
+regfi = None
+if hasattr(ctypes, 'windll'):
+    #regfi = ctypes.windll.libregfi
+    regfi = ctypes.WinDLL('libregfi.dll', use_errno=True)
+    CB_FACTORY = ctypes.WINFUNCTYPE
+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)
 
 
@@ -217,7 +231,5 @@
 
 
-# Load libregfi and define function prototypes
-regfi = ctypes.CDLL(ctypes.util.find_library('regfi'), use_errno=True)
-
+# Define function prototypes
 regfi.regfi_alloc.argtypes = [c_int, REGFI_ENCODING]
 regfi.regfi_alloc.restype = POINTER(REGFI_FILE)
