07-02-2009 10:13 AM
I have a dll function "SCTSCTL_OPEN" returns a structure like
typedef struct _sctsctl_t {
HANDLE hDevice;
//unsigned char ctl[2];
unsigned long data_in;
unsigned long data_diff;
HANDLE IsrThread;
HANDLE IsrEventHandle;
PVOID pExt;
void (*handler)(struct _sctsctl_t* board, int intvec);
} *sctsctl_t;
SCTS_API sctsctl_t __stdcall SCTSCTL_OPEN(DWORD instance);
I imported this dll with LabVIEW and vi returned a unsigned long integer shown as follow,
How do I get a return with structure? Any help would be appreicated.
Regards,
Adam
LV 8.5.1
Solved! Go to Solution.
07-02-2009 10:56 AM
07-02-2009 10:57 AM
LabVIEW doesn't support custom structures as return values.
That needn't be a problem as long as you don't want to access
members of your structures directly. LabVIEW treats it as an int
which means as an address of a plain pointer.
Try to feed this address to a function which expects a pointer
to your structure.
If you really need your struct members then you have to create some
glue code in C which exposes the required members to LabVIEW.
07-02-2009 08:42 PM
Hi bo200008,
Could you please explain in detail? I really have no idea how to make a wrapper function with LabVIEW.
Thank you!!
Adam
07-07-2009 08:05 PM - edited 07-07-2009 08:07 PM
It appears your DLL function is returning a pointer to the struct you're interested in. If other DLL functions take a pointer to this struct as an input, then you might not need to ever translate it into a LabVIEW cluster. Simply pass that pointer into the next function's input parameter.
If you do need individual access to the struct data members, however, you don't necessarily need a wrapper DLL that you program yourself in C. You can access the data directly using only LabVIEW using the Moveblock function. (See Chapter 6 of this document for more detailed info.)
This function is exported in the LabVIEW exe itself. Instead of referencing a DLL in the Call Library Function Node, just type in LabVIEW. No extension required. Then select the function Moveblock. This functions takes as an input a pointer to the source and a pointer to the destination where you'll copy the memory to, and finally the size of the memory block to copy.
You can pass in your struct pointer as the source pointer, and an appropriate LabVIEW cluster as the destination pointer with the input configuration Adapt to Type (Handles by Value). LabVIEW will then copy whatever data the struct pointer references into the LabVIEW cluster memory zone. If they match up perfectly, then that cluster will contain all the data you need. You will need to be very careful about the data sizes and arrangement in the LabVIEW cluster, or you might corrupt memory.
Here's a very ROUGH example of how to get started, but beware this example is not meant to be run immediately. You should inspect and fix any mistakes. But it will get you started if you feel like going this route. The advantage is that this is all contained in LabVIEW, and you don't need any extra DLLs to get the job done.
Example saved in LV8.6.
07-07-2009 10:55 PM - edited 07-07-2009 10:57 PM
Hi Jarrod,
The link was dead, I found this one.
www.ni.com/pdf/manuals/370109a.pdf
Could you please give this example with LabVIEW 8.5? Thanks a million~~
Adam
07-08-2009 01:43 AM
Adam1122 wrote:Hi bo200008,
Could you please explain in detail? I really have no idea how to make a wrapper function with LabVIEW.
Thank you!!
Adam
You don't typically make a wrapper function in LabVIEW but use C instead to create a DLL that contains functions to translate between neat LabVIEW datatypes and the actual original DLL dataypes
Jarrods solution is nice and can help in isolated cases but it is not a good approach if you want to interface to a complete API with many different functions who have a lot of such complicated parameters or return values.
You should be able to create what you need from the picture visible in Jarrods post. It may sound harsh and unfriendly but if that is not possible for you you will also have a lot of troubles to make something useful out of the VI Jarrod posted even if you can open it in your LabVIEW version.
Rolf Kalbermatter