ctypes, function pointers and a lot of trouble

Nick Craig-Wood nick at craig-wood.com
Wed Jun 4 16:30:21 CEST 2008


Matt <mr.edel at gmx.at> wrote:
>  Hm, thanks, now I can access my data in the functions and also write 
>  them but the program keeps terminating right at the point when the 
>  "open" function finishes. Unfortunately everything closes and I get no 
>  error messages.
> 
>  I did some additional work in the meantime and changed my code so it has 
>  the correct datatypes now:
> 
> 
>  def pystreamopen (contextH, mode, pErr):
>       print "opening..."
>       print contextH.contents.dwBufferSize #just to check the structure
>       print mode 	#tells about what the DLL wants to do with this stream

You program is crashing somewhere after here since mode is printed but
nothing else is

>       contextH.contents.mode = c_byte(5) #5=Permission to read and write
>       contextH.contents.lPos = c_uint(0) #start position
> 
>       print pErr.contents
>       pErr.contents = c_uint(0)

Try commenting out these lines and see if it works, then uncomment one
at a time.

Also is that supposed to be returning something?

>  Anyway, meanwhile  decided to try a different approach. Maybe I have 
>  more luck by having the function write the data directly into a file on 
>  the HDD.
>  Doe anyone know how to translate the following into Python/ctypes?
> 
>  I googled quite a lot before but all topic-related I found was my own 
>  posting here in this NG :S
> 
>  pFilStrm->hFile = CreateFile(	pFilStrm->szFileName,							 
>  dwDesiredAccess,								dwShareMode,									NULL,									 
>  dwCreationDisposition,
>  FILE_ATTRIBUTE_NORMAL,
>  NULL );

use os.read os.write and os.open which will give you OS handles rather
than python file objects, ie I think these are a fairly direct
interface to CreatFile etc (but I could be wrong - I'm not a windows
expert!)

-- 
Nick Craig-Wood <nick at craig-wood.com> -- http://www.craig-wood.com/nick



More information about the Python-list mailing list