LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

LV dll example help needed.

Hi All,
 
Traditionally a LabVIEW man although i have had the need to do some work in C, which i am completely un accustomed with.  I need to pass fixed precision numbers to a c module, do some fixed precision maths on it and pass it back to LabVIEW.  So, in my eagerness, I have available to me CVI.  I try to do the .dll example from LabVIEW and get to the point where i want to compile the code.  I get a whole bunch of compile errors the first two being.  Any pointers on where to go from here would be great.  I dont understand the top part of the C file in great detail , however this part was automagically written for me from LabVIEW and i could do the lower lever c bit myself (which is a fairly easy task).
 
Thanks in advance, i know this is a very fluffy post, however i feel i am out of my depth here..
 
"Declared Parameter avg_num is missing." - (highlights the first instance of avg_num)
"missing prototype" - (highlights the second occurance of _declspec)
 
/* Call Library source file */
#include "extcode.h"
_declspec(dllexport) long avg_num (float a[], long size[], float *avg);
_declspec(dllexport) long avg_num (float a[], long size[], float *avg)
 
 {
 int i;
 
    float sum = 0;
    if(a != NULL)
      {
       for(i=0; i < size; i++)
       sum = sum + a[i];
      }
    else
      return (1);
    *avg = sum / size;
    return (0);

 }
LabVIEW 2012
0 Kudos
Message 1 of 3
(3,018 Views)
Hello Craig,

Here are the problems you have:

1. You need two underscores before declspec, not one ('__declspec').

2. 'size' is declared in your function as an array. But in the for-loop inside your function, you are using it as a scalar. You probably need to change it to 'i < size[i]' or something like that.

3. NULL might not be defined in extcode.h. If it isn't, you can use 0 instead, or you can include "toolbox.h", if you're always goint to be compiling your DLL in CVI.

Also, in CVI, make sure that you go into Build>>Target Settings, click on the "Change..." button, and select "Symbols marked for export".

Good luck!
Luis
0 Kudos
Message 2 of 3
(3,000 Views)
Thankyou Luis,
 
I managed to get a look into the code again and with your help i managed to get it compiled and built within about 5 minutes.  Just the sort of step i was looking for.
Smiley Happy
Craig
LabVIEW 2012
0 Kudos
Message 3 of 3
(2,966 Views)