LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Object Oriented dll

Ok, so I need to use a dll that is object oriented.  Based on what I have read on the board, there is no way to do this directly from LV.  I assume that the 8.2 version would be of no help, since it looks to me like its OO capabilities are limited to objects created in LV.  So I assume I have to have helper functions to change to a non-OO interface.
 
 So a constructor that looks like this:

 

ClDriverWrap * pcl = new ClDriverWrap(0);

 

Would need a function that looks like:
 
ClDriverWrap* clDriverWrapCreate()
{
     return new ClDriverWrap(0);
}
 
Then to call a member function that looks like this:

 

ClDriverWrap::MonitorEnableRt (unsigned short uRtAddress,

                                         bool bEnable)

 

Would need a function that looks like:

 

bool EnableRTMonitor(ClDriverWrap* ptr, unsigend short _uRtAddress, bool _bEnable)

{

     return ptr->MonitorEnableRt (_uRtAddress, _bEnable);

}

 

Where ptr is the U32(?) returned from the constructor.  Am I on the right track here?

 

Thanks,

Bill F

 

0 Kudos
Message 1 of 3
(3,231 Views)

Hello,

I don't have experience with this, but I would suggest creating a trivial class containing just a single data member, a constructor which initializes it, and an accessor method which returns its value.

Once you get things working with that simple class, you should be able to extend the idea to others.

What you described/exemplified seems to make sense though - you have a wrapper function which returns your pointer to your object, and a wrapper function for each member function of that object's class which takes the pointer as an argument, in addition to the function's original arguments, and uses the pointer to call the original function with those original arguments.  Then to use the dll, you call the function to get your object pointer first, and then use it to call the other wrapper functions.

Is that the general idea you are going for?

If you do play with a simple example, please post it for the community!

Best Regards,

JLS

Best,
JLS
Sixclear
0 Kudos
Message 2 of 3
(3,204 Views)
All I can say to this is that it is what I would do, aside from cosmetics such as if the Create function should return the object pointer as return value or a parameter passed by reference.

Basically for every method you need to access you create a C function that takes as first parameter the object pointer itself. And then of course you need an allocator and a deallocator function.

One common thing to do in such cases is to name the accessor functions with the object name in its name too.
Something like :

ClDriverWrap* ClDriverWrap_Create(void);
bool ClDriverWrap_MonitorEnableRt(ClDriverWrap* ptr, unsigned short uRtAddress, bool bEnable);bool ClDriverWrap_Dispose(ClDriverWrap* ptr);

And in LabVIEW you treat the ptr as an U32 or maybe even better yet create a specific refnum based on a datalog refnum with a unique enum placed inside with a single value that can be the name or an abbreviation of your class object.

Rolf Kalbermatter

Message Edited by rolfk on 11-22-2006 10:37 AM

Rolf Kalbermatter  My Blog
DEMO, Electronic and Mechanical Support department, room 36.LB00.390
0 Kudos
Message 3 of 3
(3,192 Views)