05-04-2015 09:35 AM - edited 05-04-2015 09:37 AM
I have a dll with an function like the following, I need to call.
#define COUNT 16
typedef UINT32 Status;
typedef UINT32 DeviceHandle;
typedef struct SetRcvFilterReq
{
UINT16 mask[COUNT];
} T_SetRcvFilterReq;
typedef struct RcvFilterResp
{
UINT16 status;
} T_RcvFilterResp;
API Status API_CALL SetRcvFilter(DeviceHandle handle, T_SetRcvFilterReq rcvFilter, T_RcvFilterResp *response);
I tried to manage it like it is descripbed in the "Simple Struct (with basic datatypes);Passing a parameter (Pass by value)" i found here:
https://decibel.ni.com/content/docs/DOC-9079
But it doesn't work to my problem. I always get the Error 1097.
Any Ideas?
Solved! Go to Solution.
05-04-2015 01:42 PM
There's no need to do the crazy array manipulation, then index out the individual elements. If you just need to pass 16 0's as parameters, wire a 0 constant to all 16 inputs. That said, are you sure the function prototype is correct? Normally you would pass a struct by pointer, not by value.
Have you already checked the calling convention, and tried setting the error checking level to maximum?
It would help if you post the entire header (.h) file and your VI, along with any documentation for the functions you are trying to call.
05-05-2015 02:26 AM
Hi nathand!
My Problem is exactly how I need to counfigure the CLFN! The the struct is passed by value and not by reference and it contains an array, so i don't know if i did right. If I'm try to use an array or a cluster, the CLFN alwas want to pass the value by reference.
Yes, i Thet the error checking level to maximum and the CLFN returns the error 1097: "LabVIEW: An exception occurred within the external code called by a Call Library Function Node. The exception might have corrupted the LabVIEW memory. Save any work to a new location and restart LabVIEW."
05-05-2015 03:57 AM
@Tobias_BSH wrote:
Hi nathand!
My Problem is exactly how I need to counfigure the CLFN! The the struct is passed by value and not by reference and it contains an array, so i don't know if i did right. If I'm try to use an array or a cluster, the CLFN alwas want to pass the value by reference.
Yes, i Thet the error checking level to maximum and the CLFN returns the error 1097: "LabVIEW: An exception occurred within the external code called by a Call Library Function Node. The exception might have corrupted the LabVIEW memory. Save any work to a new location and restart LabVIEW."
This would be in fact a pretty unportable configuration. Passing a struct by value means all its individual elements are passed on the stack. However for an array of uint16 this begs the question if each uint16 is passed as individual parameter value or rather two uint16 combined into a 32 bit parameter for 32 Bit LabVIEW and four uint16 combined into a 64 Bit parameter for 64 Bit LabVIEW. I would personallly guess that it is the latter. However I'm not sure C actually mandates one above the other and it is quite possible that different C compilers do this rather differently (and some might even choose to promote it to a pointer anyways!
In short, the C standard is pretty unspecific in such things and leaves a lot of freedom to compiler developers for specific implementations. That is not a flaw of C but on purpose to allow C compiler builders to adapt their compiler in various ways to the actual implemenation that is best suited to a particular CPU hardware architecture. C doesn't even mandate that a byte is always 8 bit (and for some arcane hardware architecture it wasn't!)
Personally this API is something that while it probably can be made to work by packing the array elements in natural elements for the target architecture and then passing them as individual parameters to the function, is certainly something I would never rely on being consistent between different C compilers (and even C compiler versions).
So try to create 8 uint32 values from those 16 uint16 values and pass them as 8 individual parameters to the function (4 uint64 parameters if you happen to run in 64 Bit LabVIEW). It may work, but is a really horrible API definition.
05-05-2015 04:14 AM
Hi Rolf!
Thanks for your help. Create 8 uint32 values from those 16 uint16 values works.