I am working on creating a python API for a dll for a daqboard we have here.  I have the documentation for the library, as well as the C, Delphi and VB api.  I have decided to use ctypes for the project, and most is working out alright.  However I have run in to considerable headaches when dealing with pointers to arrays.  The function I am first working with, requires a pointer to an array of strings that will contain the names of all the devices installed.  Here is a snippet of the code I have so far:<br>
<br clear="all">def GetDeviceList():<br>    """Returns a list of currently configured device names"""<br><br>    devices = []<br>    count = GetDeviceCount()<br>    countpnt = ct.pointer(ct.c_int(count))<br>
    devlist = (ct.c_char_p * count)()<br>        <br>    daq.daqGetDeviceList(devlist, countpnt)<br>    <br>    for i in devlist:<br>        devices.append(i)<br>        <br>    return devices<br><br>Using Python 2.6.3 the IDLE goes into an infinite loop of, from what I can gather, Tkinter errors, and Im unable to kill the command to actually read all of the errors.<br>
<br>When using Python 3.1.1, I get this error:<br><br>Python 3.1.1 (r311:74483, Aug 17 2009, 17:02:12) [MSC v.1500 32 bit (Intel)] on win32<br>Type "copyright", "credits" or "license()" for more information.<br>
>>> import daqX<br>>>> daqX.GetDeviceList()<br>Traceback (most recent call last):<br>  File "<pyshell#1>", line 1, in <module><br>    daqX.GetDeviceList()<br>  File "C:\Python31\daqX.py", line 54, in GetDeviceList<br>
    for i in devlist:<br>ValueError: invalid string pointer 0x42716144<br>>>> <br><br>I am really at a loss here, so any insight at all would be great.  Something odd though, is that when I pass just c_char_p instead of an array of c_char_p, I receive the one device I have installed on this computer, and it works great.  However, when I make an array of just one item, I get these odd errors.<br>
<br>-- <br>Nathaniel Christopher Hayes<br>Third Year Mechanical Engineering<br>Email: <a href="mailto:nathaniel.hayes@maine.edu">nathaniel.hayes@maine.edu</a><br>