Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Re: ctypes issues involving a pointer to an array of strings

Thread Tools

Re: ctypes issues involving a pointer to an array of strings

Posts: n/a
Nathaniel Hayes wrote:
> On Tue, Oct 20, 2009 at 2:08 PM, MRAB <(E-Mail Removed)
> <mailto(E-Mail Removed)>> wrote:
> Nathaniel Hayes wrote:
> On Tue, Oct 20, 2009 at 12:12 PM, MRAB
> <(E-Mail Removed) <mailto(E-Mail Removed)>
> <mailto(E-Mail Removed)
> <mailto(E-Mail Removed)>>> wrote:
> The digits in that pointer value look suspiciously like the
> character
> codes of a string rather than an actual address:
> >>> "\x42\x71\x61\x44"

> 'BqaD'
> It looks like the first 4 characters of a string starting
> 'DaqB' are
> being used as a string pointer on a little-endian platform.
> 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.
> Well, the name of the device is DaqBoard2K, so thats where the
> DaqB is coming from. That means that the function worked, but I
> can seem to get the information in a usable format. I'm not
> well versed in C or anything low level like that, so not really
> sure what is going behind the scenes. I have seen
> (c_char_p*4)() would make an iterable ctypes array of 4 c_char_p
> variables, but it seems like the address to the string has been
> overwritten by the string itself?
> What does the documentation of the C API actually say? What does the
> parameter list of the C function look like?
> --
> daqGetDeviceList(DaqDeviceListT *deviceList, DWORD *deviceCount);
> Is the prototype. And the documentation:
> Function Usage
> The daqGetDeviceList function will return the device names in the
> deviceList parameter for the number
> of devices returned by the deviceCount parameter. The deviceList entry
> contains an array of device names
> each consisting of up to 64 characters. Each device name can then be
> used with the daqOpen function to open the
> specific device. The DaqDeviceListT parameter must point to an
> appropriately sized memory area which can
> hold all the names for all the configured devices before calling this
> function. If it is not known how many devices
> are configured, then call the daqGetDeviceCount function before calling
> this function.

It says "contains an array of device names", which to me sounds like you
need to give it a block of memory into which it will copy the names (max
64 characters/name). This will also explain why your test with Python 3
gave the characters of a name which you thought was a pointer to the

The definition of DaqDeviceListT will tell you exactly what you need (it
might be an array of 64 chars or an array of n such entries, for

The deviceCount parameter is a pointer too, so that suggests to me that
you tell it how many names you want and on returning it will have set
that to the number it has actually returned.
Reply With Quote

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
How to correctly pass “pointer-to-pointer” into DLL via ctypes? Grigory Petrov Python 4 10-27-2012 02:22 PM
Re: ctypes issues involving a pointer to an array of strings MRAB Python 0 10-20-2009 04:12 PM
WindowsXP/ CTypes - How to convert ctypes array to a string? Python 0 08-19-2008 10:20 AM
confusion involving pointer to pointer when converting from derived to base Kavya C++ 2 12-23-2006 07:31 PM
ctypes pointer to pointer Podi Python 2 09-28-2006 04:45 PM