LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

pointer to structure within a structure in LabVIEW

Solved!
Go to solution

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;

Thoric (CLA, CLED, CTD and LabVIEW Champion)


0 Kudos
Message 1 of 5
(3,502 Views)
Solution
Accepted by topic author Thoric

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.


___________________
Try to take over the world!
Message 2 of 5
(3,489 Views)
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!
Thoric (CLA, CLED, CTD and LabVIEW Champion)


0 Kudos
Message 3 of 5
(3,481 Views)

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. 

Message Edited by rolfk on 10-25-2009 03:43 PM
Rolf Kalbermatter  My Blog
DEMO, Electronic and Mechanical Support department, room 36.LB00.390
Message 4 of 5
(3,469 Views)

rolfk wrote: So your LabVIEW cluster, if you need to define it as such, will need to be different depending on the LabVIEW bitness you use. 

Oooo. That makes things a little more complicated - thanks for the heads up! Smiley Happy

Thoric (CLA, CLED, CTD and LabVIEW Champion)


0 Kudos
Message 5 of 5
(3,423 Views)