11-05-2013 12:48 PM - edited 11-05-2013 12:54 PM
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!
11-05-2013 03:21 PM
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.
11-06-2013 02:01 AM
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