10-24-2009 10:38 PM
I've not used the LabVIEW call library function very often, so I've quickly found myself up against a problem which may, or may not, be easy to solve (for someone into C code that is).
I'm calling a dll which requires a structure pointer as an input. This i can provide by creating a cluster and using "Adapt to Type" for the dll call input terminal. This passes a pointer for the cluster (structure) to the dll. However, the structure is meant to contain pointers to other structures! So now I'm stuck, because I don't know how to create LabVIEW clusters that contain pointers to other LabVIEW clusters.
Is this even possible?
In the source file, the structure definition looks like this:
typedef struct DmtxEncode_struct {
int method;
int scheme;
int sizeIdxRequest;
int marginSize;
int moduleSize;
int pixelPacking;
int imageFlip;
int rowPadBytes;
DmtxMessage *message; <-- Pointer to another structure!
DmtxImage *image; <-- Pointer to another structure!
DmtxRegion region;
DmtxMatrix3 xfrm;
DmtxMatrix3 rxfrm;
} DmtxEncode;
Solved! Go to Solution.
10-25-2009 03:05 AM
My own experience with this is limited, but a pointer is basically just a number which represents an address in memory (a 32 bit number in a 32 bit system).
Depending on what the function you call does with the pointer, you might be OK with even giving it a null pointer, but because you have no way of knowing for sure what the function is doing or will be doing in the future, you should give it the correct pointer.
How do you do that? Well, you need to get the pointer to the relevant structure and for that you will need to allocate the structure. If the DLL you're using has a function which allocates the memory for the structure and returns a pointer to it, you're in luck - just take that pointer and put it in the cluster. If it doesn't have such a function, I believe you'll have to write and compile one in C yourself.
That said, others with more experience might have an easier solution.
10-25-2009 05:30 AM
10-25-2009 09:43 AM - edited 10-25-2009 09:43 AM
Thoric wrote:
You are so right! I was mistakenly thinking I needed to create all the structures within LabVIEW, but the DLL creates those that are referenced by pointers, so I only need to provide an I32 for each pointer. I'll give this a go later as soon as I get a chance and mark your solution if it works. Thanks tst!
If you work in LabVIEW 8.6 or higher you will have to account for the difference in pointer size for 32 bit and 64 LabVIEW. A pointer in 32 bit LabVIEW is .. surprisingly 32 bit large and in 64 Bit LabVIEW .. yes indeed 64 bit long. So your LabVIEW cluster, if you need to define it as such, will need to be different depending on the LabVIEW bitness you use.
10-26-2009 11:23 AM