correct form of struct for strings (or byte array) when importing Labview DLL into python (using ctypes)
<p>I'm trying to import a DLL (created in Labview) into python. 
I've reduced it to a very simple Labview VI, a string goes into a cluster, the cluster is a function in the DLL i.e. the function is: void TestCluster(Cluster *outputCluster)
I can get everything but strings and arrays to read in from a cluster. I think I just don't have the correct Struct (?).</p>

<p>Has anyone done this? There's a partial guide: 
<a href="http://www.ni.com/white-paper/8911/en/" rel="nofollow">http://www.ni.com/white-paper/8911/en/</a></p>

<p>It might also be due to my little knowledge of ctypes in Python too.</p>

<p>Sample Python code for the import:</p>

<pre><code>#!/usr/bin/env python
import sys, os, string
from ctypes import *

class byteArrayStructure(Structure):
    _fields_ = [("dimSize", c_int),("bytes", c_uint8 )]

class clusterStructure(Structure):
    _fields_ = [("stringField", c_char*4 ),
                ("byteArray", byteArrayStructure )]

dll = cdll.LoadLibrary("test.dll")
libc = cdll.msvcrt

def testMain():
    retValue = 0
    try:
        clusterIn = clusterStructure()
        dll.TestCluster( byref(clusterIn) )

        print clusterIn.byteArray.bytes 
        print cast(clusterIn.byteArray.bytes,c_char_p)

    except ValueError, Argument:
        retValue = "Error: " + str(ValueError) + "  " + str(Argument)
    return retValue

testMain()
</code></pre>

<p>edit:</p>

<p>structs from test.h,</p>

<pre><code>typedef struct {
    int32_t dimSize;
    uint8_t elt[1];
} Uint8ArrayBase;
typedef Uint8ArrayBase **Uint8Array;
typedef struct {
    LStrHandle elt1;
    Uint8Array unsignedByteArray;
} Cluster;

void __cdecl TestCluster(Cluster *outputCluster);

MgErr __cdecl LVDLLStatus(char *errStr, int errStrLen, void *module);

/*
* Memory Allocation/Resize/Deallocation APIs for type 'Uint8Array'
*/
Uint8Array __cdecl AllocateUint8Array (int32 elmtCount);
MgErr __cdecl ResizeUint8Array (Uint8Array *hdlPtr, int32 elmtCount);
MgErr __cdecl DeAllocateUint8Array (Uint8Array *hdlPtr);
</code></pre>

<p>Thanks :)</p>