LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Call Library Node

Hi everybody!

 

I would like to receive a structure from a DLL.

So I created a little C program with two structures.

 

#include <stdio.h> 
#include "extcode.h"

#ifdef __cplusplus
extern "C" {
#endif

struct simpleStructCircle
{
	float x;
	float y;
	float radius;
};


struct simpleStructCircle ReturningAValue_SimpleStruct_1(void)
{
	struct simpleStructCircle circle = {1, 1, 3};
	return circle;
}

struct simpleStructCircle ReturningAValue_SimpleStruct_2(void)
{
	struct simpleStructCircle circle_2 = {1, 1, 3};
	return circle_2;
}

int __declspec(dllexport) main(void)
{
	ReturningAValue_SimpleStruct_1;
	ReturningAValue_SimpleStruct_2;
}

#ifdef __cplusplus
}
#endif

 Next I generated the DLL. (attachment)

 

But when I call it with call library function node I only see the main function and not the functions  ReturningAValue_SimpleStruct_1 and ReturningAValue_SimpleStruct_2.

Do you have an idea?

Thx a lot for your time!

 

Function_tab.jpg

 

 

Download All
0 Kudos
Message 1 of 3
(2,703 Views)

I think the problem is that the only function you declared as dllexport is the main function, so that's the only one that's exported and shows up in the Call Library Function dialog box. You need to export all the functions that you want to call from LabVIEW. I don't know if you'll be able to export a function that returns a struct by value, though - you may need to return a pointer to it (which will make memory management difficult), or make it a parameter passed by pointer which is a better and more standard solution.

Message 2 of 3
(2,680 Views)

Ok I found my problem.

 

The exportation call shall be placed at the begining of the function.

 

#include <stdio.h> 
#include "extcode.h"

#ifdef __cplusplus
extern "C" {
#endif

struct simpleStructCircle
{
	float x;
	float y;
	float radius;
};


__declspec(dllexport) struct  simpleStructCircle ReturningAValue_SimpleStruct_1(void)
{
	struct simpleStructCircle circle = {1, 1, 3};
	return circle;
}

__declspec(dllexport) struct  simpleStructCircle ReturningAValue_SimpleStruct_2(void)
{
	struct simpleStructCircle circle_2 = {5, 6, 158};
	return circle_2;
}

int __declspec(dllexport) main(void)
{
	ReturningAValue_SimpleStruct_1;
	ReturningAValue_SimpleStruct_2;
}

#ifdef __cplusplus
}
#endif

 

0 Kudos
Message 3 of 3
(2,658 Views)