LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

DLL C/C++ syntax for Call Library Function Node

Hello,

 

I am interested in calling DLL from Labview and found several intersting tutorials on the Call Library Function Node. One interesting tutorial is Building a DLL with Visual C++ http://zone.ni.com/devzone/cda/tut/p/id/3056

 

One can notice in the example presented in this tutorial that the parameters that are outputs of the exported function are of type pointers. And I am curious about the theory behind this. 

 

I looked also at the example in LabVIEW Call DLL.vi and it seems that all outputs are pointers to the desired data type.

 

I tried to write a short code where I assign a new value for one parameter in the export function. But this value is not updated in Labview. To make it clear: assume 50 is passed to an input parameter (on the left side of the Call Lib func Node). In the function, i assign 100 to this variable and expect this value on the output in Labview (right side indicator of Call Node) but the output remains 50.

 

I am trying to change my code but i get errors in linking (compiling is ok) that I cannot understand. LINK : fatal error LNK1168: cannot open Debug/DoseDLL.dll for writing
Error executing link.exe.

 

I don't get any error with the code provided in the above tutorial Smiley Happy  so i am trying to reproduce a similar code...

 

Thank you

 

 

 

0 Kudos
Message 1 of 9
(5,195 Views)

Without looking at your C code it's hard to comment on what you may have done incorrectly. I'm not sure I understand why you're asking this:


One can notice in the example presented in this tutorial that the parameters that are outputs of the exported function are of type pointers. And I am curious about the theory behind this. 

How else would you do it? I assume you understand the premise of pointers in C? 

0 Kudos
Message 2 of 9
(5,181 Views)

Hello,

 

Please find attached the source code in C, the DLL and the vi. 

 

you notice in the C code that I set variable dose=100 and this is the value I would like to export as an output for labview (right side of Node) for whatever value in the input (i put 50 for input dose). In the current code, the same value of input dose (50) is passed to the output (i assume it has to do with the reference ?). The idea is that variables dose and rate should be set/calculated in the DLL function. 

 

Thank you!

Download All
0 Kudos
Message 3 of 9
(5,160 Views)
The argument dose is being passed by value. Thus, any "changes" made in the DLL are not reflected in LabVIEW. You have to pass the argument as a pointer, just like the rate argument.
0 Kudos
Message 4 of 9
(5,153 Views)

This is what I thought of and I have been trying some turnarounds.. I am sorry if this thread is more about C than Labview...

 

I passed the argument dose as a pointer as in the following code but the DLL does not build successfully. I am not sure if the pointer to dose has been initialized properly.. 

 

__declspec(dllexport) int __cdecl MainFunction (int weight, int conc, double* dose, double* rate)
{
    double intdose=100;
    *dose=100;

   *rate= Getrate(weight, conc, intdose);
    return true;
}

 

Thank you very much

0 Kudos
Message 5 of 9
(5,146 Views)

What compiler are you using?

What was the error when trying to build the DLL? As for the code, I don't see anything really wrong with it, and it compiles just find in Visual C++ 2008 Express.

 

 

0 Kudos
Message 6 of 9
(5,138 Views)

Beetho,

 

The building of the DLL shouldn't be related to the pointer being initialized, since that's a runtime thing.  When you changed the code, did you change both the prototype and the definition of the function?  I can't think of any other reason that the build would fail except a syntax error. 

Jared S.
Applications Engineering
National Instruments
0 Kudos
Message 7 of 9
(5,117 Views)

Hello,

 

Yes I did change the prototype and the declaration. No syntax error was found. 

 

I am using MS Visual C++ 6.0. I will install the Express on my own computer and test the code.

 

cheers!

 

 

0 Kudos
Message 8 of 9
(5,093 Views)
Sorry, I just saw the error code that you posted.  LNK1168 is a permissions error for writing the DLL.  Try backing up DoseDLL.dll and remove it from that folder.  Then rebuild the project.  You should also check the permissions on the file itself.
Jared S.
Applications Engineering
National Instruments
0 Kudos
Message 9 of 9
(5,079 Views)