【发布时间】:2021-11-21 10:57:18
【问题描述】:
我想将 DLL 导入 LabVIEW 并从我的函数创建 VI,但对于具有常见数据类型的简单函数,导入效果很好。我的问题是当函数具有结构数据类型时。
我关注this tutorial导入。
我的 DLL 文件:
test.h:
#ifndef TEST_H_
#define TEST_H_
typedef struct
{
int r_sum;
int r_minus;
int r_multiply;
float r_divide;
}CALC_t;
int sum(int a, int b);
int minus(int a, int b);
int multiply(int a, int b);
float divide(int a, int b);
CALC_t calc_all(int a, int b);
#endif /* TEST_H_ */
test.c:
#include "test.h"
int sum(int a, int b)
{
return a+b;
}
int minus(int a, int b)
{
return a-b;
}
int multiply(int a, int b)
{
return a*b;
}
float divide(int a, int b)
{
return (float)a/b;
}
CALC_t calc_all(int a, int b)
{
CALC_t result;
result.r_sum = sum(a, b);
result.r_minus = minus(a, b);
result.r_multiply = multiply(a, b);
result.r_divide = divide(a, b);
return result;
}
当我导入DLL时,函数sum、minus、multiply和divide的VI创建成功,并且运行良好。但是函数calc_all没有被创建,LabVIEW显示警告信息:
Cannot create VI
The following VI cannot be created. This might indicate that the associated function contains
parameters of a data type that cannot be converted directly. To work around this issue, you can
create a custom control or typedef control to represent a complex structure or multidimensional
array, then re-run the Import Shared Library wizard and select Update VIs from a shared library.
Using the same shared library, step through the wizard again. On the Configure VIs and Controls
page, assign the custom control or typedef to the associated parameter(s). Complex structures
include nested structures, structures containing arrays, arrays of strings, and multidimensional
arrays.
dll_calc_all.vi
我尝试在配置 VI 和控件页面上进行更改,分配自定义控件、簇和其他数据类型,但没有成功。
我用cygwin32用Eclipse IDE编译库,我的LabVIEW是LabVIEW 2021 32 bits。
【问题讨论】:
标签: c struct dllimport labview