LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

What does a DLL wrapper actually do?

I have a library DLL that I have to talk to in order for my current project to work.  Unfortunately, several of the functions I need to use return pointers to arrays of structures.  The structures are pretty simple (three uint32s) and the arrays are variable lengths but at least I know what length they're supposed to be for a particular instance.  After quite a bit of research I've ascertained that I will need to get a copy of VC++ and write a "wrapper" DLL to do some data translation. 
 
My question is...how does a wrapper work?
 
I'm confused about the actual dataflow from LabVIEW to the wrapped target shared library and back.  Does the wrapper take the LV datatype (presumably an array of clusters), convert it to something that the library can deal with (a pointer to an array?), call the library, get the library's return (a pointer) and then convert it to something LV can deal with (like another array of clusters)? 
 
If it's not obvious, I'm not a C programmer (yet).  I've looked at several tutorials here, a dozen or so examples, a lot of comments and I still don't see what a wrapper is being asked to do.  Can any of you experieced wrapper-writers shed some light for me?
 
Thanks,
Tim
 
0 Kudos
Message 1 of 5
(12,566 Views)
"My question is...how does a wrapper work?"

Pretty much any way you want it to work, really. Smiley Happy

In most cases a wrapper DLL is used to handle data types since C is a bit "loose" with datatypes, and LabVIEW stores data differently. In your specific case, I don't think you need a wrapper DLL since your structures contain only integers. You should be able to pass the array of clusters directly to the DLL, though you may want to consider a second input/output that is the size of the array. Have you seen this article: Passing an Array of Clusters from LabVIEW to a DLL.
Message 2 of 5
(12,548 Views)
It would be great if I could use these functions without writing any C code.  I played with the concept in that KB article quite a bit, but still couldn't get a return out of any function.  I've been playing a lot with one particular function.  If I pass the array of clusters to the function without initializing it I got an "Illegal Null Pointer" error from the library.  If I entered some dummy data into the array, the function returns an identical array with the same data.  It was at about that time that I started looking into the wrapper thing.
 
Maybe I'm doing this all wrong from the start.  Allow me to cast out a few details with the hope that someone can spot a mistake:
 
The function prototype looks like this:
 
uint32 AcqRecordRead ( uint32 hChannel, uint32 RecCount, pvoid pRecordBuff, puint32 pBuffTotal ) .

The prototype that the Call Library Function node is showing me after configuaration looks like this:

unsigned long AcqRecordRead(unsigned long HChannel, unsigned long RecCount, void *RecordBuff, unsigned long *BuffTotal);

Hchannel is a handle that is acquired from a previous function.

RecCount tells the function how many records to return - presumably it's the number of elements in the output array.

pRecordBuff is the pointer to the array of structures of three uint32s that is the actual data that I'm trying to acquire.  It's being input as 'adapt to type'.

pBuffTotal is the number of records actually returned by the function (the length of the array pRecordBuff points to).  During all of my experimentation, I've never seen this output exceed zero (sigh).

See anything obviously wrong? 

Thanks,

Tim

 

 

0 Kudos
Message 3 of 5
(12,524 Views)
The prototype seems correct. You definitely have to initialize the array since you have to allocate memory for it, and the function is probably assuming the memory has been pre-allocated. I'm assuming you're initializing and passing the values this way:



The function should only update as many array elements as it collected.

It also seems that you're trying to use a 3rd party data acquisition function. Presumably this means you have a non-NI board (not that there's anything wrong with that. Smiley Happy). Are you sure you're using the functions in the proper order, and are not missing some other call, like starting the acquisition? Do you have some example code (like in C or VB) from the manufacturer that shows you the proper sequence of function calls?


Message Edited by smercurio_fc on 04-28-2008 04:06 PM
0 Kudos
Message 4 of 5
(12,521 Views)

Yeesh.  Turned out to be a hardware problem.  The test transmitter I'm using defaults to a different speed than the reciever I'm programming. 

I probably wouldn't have checked that without your input...instead I'd be banging my head against a C++ command line and pestering people needlessly about wrappers and declspecs.  Thanks.

 

 

0 Kudos
Message 5 of 5
(12,480 Views)