[Pyrex] New to Pyrex: how to I make strings as attributes?

Lennart Regebro regebro at nuxeo.com
Sat Oct 30 10:21:15 CEST 2004


I'm currently trying to wrap some windows methods in a nice object, but 
I have trouble with strings.

basically, this is what i do (slightly shortened:)

cdef extern from "mmsystem.h":
     ctypedef struct MIDIINCAPS:
         int wMid # manufacturer ID
         int wPid # product ID
         int vDriverVersion # version of the driver
         char szPname[32] # product name (NULL terminated string)

     MMRESULT midiInGetDevCaps(UINT uDeviceID, MIDIINCAPS *mic, UINT cbmic)

cdef class outPort:

     cdef public int port
     cdef public int manufacturer_int # manufacturer ID
     cdef public int product_int # product ID
     cdef public int driver_version_int # version of the driver

     def getPortInfo(self):
         cdef MIDIINCAPS mic
         midiInGetDevCaps(self.port, &mic, sizeof(MIDIINCAPS))
         self.manufacturer_int = mic.wMid
         self.product_int = mic.wPid
         self.driver_version_int = mic.vDriverVersion

Now, this is all fine. But how do I get that pesky char szPname[32] into 
a python accessible string attribute? Nothing I tried would both compile 
and return the string in question when accesed from python...

trust me: more questions woll follow. the documentation is fine by 
normal python standards, meaning it's still slightly lacking.. :-)





More information about the Pyrex mailing list