02-21-2010 04:58 PM
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 so i am trying to reproduce a similar code...
Thank you
02-21-2010 10:39 PM
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?
02-22-2010 09:43 AM
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!
02-22-2010 10:47 AM
02-22-2010 11:20 AM
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
02-22-2010 12:48 PM
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.
02-22-2010 06:01 PM
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.
02-23-2010 12:56 PM
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!
02-23-2010 05:10 PM