471,330 Members | 1,891 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,330 software developers and data experts.

ctypes help for "array of character pointers" as an output parameter

I'm wrapping a C function exists in a shared library. Its prototype
looks like as follows

int getFileNames(int aSize, char **names);

The documentation says that the asSize is the number of entries to be
returned and
names is output array of character pointers of at least aSize
elements. So, I defined
a function prototype in python, follow ctypes tutorial, and try to run
it. The following
code section shows what I did.

_getNames = TheLib.getNames
_getNames.restype = c_int
_getNames.argtypes = [
c_int,
POINTER(c_char_p)
]

def getNames():
aSize = 1024
names = (c_char_p * arraySize)()
rc = _getNames(aSize, names)

After that, I make a call to getNames() in my python program and,
unfortunately, either TypeError
or Segmentation fault. Sigh...

I wonder that whether the _getNames prototype definition in my code
section is correct??
If it isn't, I guess so, how do I do a right one?
Another, whether the usage in getNames() is correct??
Appreciate for any reply or recommendation.

Jun 23 '07 #1
0 903

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Simon Morgan | last post: by
3 posts views Thread by Jess | last post: by
reply views Thread by rosydwin | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.