08-24-2011 04:59 AM
Hi !
I wanted to say hi for first time here : )
I have a huge problems with calling a DLL in my VI. Of course I've read everything about that and I'm sure I did it right. Especially it worked for some time, but magically LV stopped reading the file and sending it further... The int_32 to send to number of columns is always 0. Which is weird. Maybe I deleted something... I run out of the ideas. Any guesses ?
Another problem is that after sending data (arrays) to the DLL - it sends it wrong somehow. I know it's LV fault and not the code because I used the DLL with cpp programme I made.
08-24-2011 09:27 AM
Unfortunately, that's not enough information to discern what's going on. All you've said is "it used to work, now it doesn't". And "it sends it wrong somehow" means what exactly? Do you see any errors? What does the DLL do? Does the C program do the same thing LabVIEW does?
08-24-2011 09:37 AM
Yes it does. Well, I tried to debug it with VS and it gives error in this point : >msvcr100.dll!free(void * pBlock) Line 51C It doesn't even step into the read file function. The c programme does the same as VI.
It did work some time before - although not in the way as C programme. As if the values given to DLL functions in arrays were different.
08-25-2011 04:31 AM
Ok - another question. How exactly does LV read DLL ? Does it close a DLL after it goes out of the DLL node ?
Suppose we have two DLL nodes connected by a chain (error in, error out) - is it : readDLL -> read arguments to function -> does function -> return(); -> close DLL -> load DLL(second node) -> -> read arguments to function -> does function -> return(); -> close DLL;
if yes - how not to close DLL after going out of the first node ? Becuase that ereases the memory and objects.
08-26-2011 12:34 PM
LV doesn't release the dll until you close the VI.
The trick to pass data in/out from LV to dll is: right click the CLF node, and create the .c prototype.
Use the prototype in your C++ compiler.
08-26-2011 04:44 PM
If I understand you right - I have to create a file .c with only prototypes of the functions ? What about the DLL ? I'll try to read about that tool, but please expand a bit. : )
D
08-26-2011 06:24 PM
You can export as many functions as you want from the dll.
But for those functions to be used in LabVIEW, use the LabVIEW generated prototypes.
08-29-2011 10:59 AM
Hi ,
Thanks for that advice, but to assess if helped or not I want to ask how I can convert char array[] to char* array ?
The reason for is that I left the DLL I wanted to work with LV and I wrote a new one - a level upper to use the old DLL and to work with LV, this time with LV prototypes. The thing is, that in old DLL I pass char * arrayname to one function and LV needs char array[]. I've read that this is the same in fact, because only pointer is passed to function in both cases. Of course there is a case of terminating NULL at the end of char *.
08-29-2011 02:36 PM
Both array[] and *array1 can be used to represent an array. You have to allocate memory for the pointer *array1.
Then
strcpy(array1, array);
If you want to pass the LabVIEW path control into a dll, simply wire the path to the dll, in configure, choose adapte to the input.
The prototype will be: Path mypath. In C/C++,
void Function(Path mypath)
{
#include "extcode.h"
char szPath[MAX_PATH];
SPrintf(szPath, "%z", mypath);
......
}
08-29-2011 03:11 PM
Ok, I've read about sprintf, but I can not see what "z" option stand for. Also - how is it possible to pass a type "Path" to Visual Studio ? It won't recognize it for sure. Also - MAX_PATH - well, the length of file path can be long - shall I just assess it ? The code will be vulnerable to crashes.