From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.
We appreciate your patience as we improve our online experience.
From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.
We appreciate your patience as we improve our online experience.
请教各位大神一个问题,现有这样一个dll,其代码如下:
typedef struct {
double DBL;
int INT;
} TD2;
_declspec(dllexport) void CLUSTERArray(TD2 *input, TD2 *output[2])
{
output[0]->DBL = input->DBL * input->DBL;
output[1]->DBL = input->DBL * input->DBL;
output[0]->INT = input->INT * input->INT;
output[1]->INT = input->INT * input->INT;
}
当我使用LabVIEW进行调用时出错(采用了两种方式分配返回参数的内存均报错),LabVIEW调用方式如下:
已解决! 转到解答。
如果函数原型是像下面这样写的话是可以成功调用的
typedef struct {
double DBL;
int INT;
} TD2;
_declspec(dllexport) void CLUSTERArray(TD2 *input, TD2 *output)
{
output->DBL = input->DBL * input->DBL;
output->INT = input->INT * input->INT;
}
Try:
_declspec(dllexport) void CLUSTERArray(TD2 input, TD2 *output1, TD2 *output2)
Use "External C" to avoid function name mangling.
_declspec(dllexport) void CLUSTERArray(TD2 *input, TD2 *output[2])/*如果这里的[2]不要了,那我下面的函数主体里该怎么写才能体现output是个数组呢*/
{ output[0]->DBL = input->DBL * input->DBL;
output[1]->DBL = input->DBL * input->DBL;
output[0]->INT = input->INT * input->INT;
output[1]->INT = input->INT * input->INT;
}
函数改为下面这种方式后,调用Dll不在报内存错误,但是返回的output数组只有第一个元素是对的,如下图所示。
_declspec(dllexport) void CLUSTERArray(TD2 *input, TD2 output[2])
{
output[0].DBL = input->DBL * input->DBL;
output[1].DBL = input->DBL * input->DBL;
output[0].INT = input->INT * input->INT;
output[1].INT = input->INT * input->INT;
}