I'm trying to call an external library function that returns a NULL-terminated array of NULL-terminated strings.
kernel32 = ctypes.windll.kernel32
buf = ctypes.create_unicode_buffer(1024)
length = ctypes.c_int32()
if kernel32.GetVolumePathNamesForVolumeNameW(ctypes.c_wchar_p(volume),
buf, ctypes.sizeof(buf), ctypes.pointer(length)):
## ???
In other words:
buf = ctypes.create_unicode_buffer(u'Hello\0StackOverflow\0World!\0')
How do I access all contents of buf
as a Python list? buf.value
only reaches up to the first NULL.
In C it would be something like this:
while (*sz) {;
doStuff(sz);
sz += lstrlen(sz) + 1;
}