LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

DLL C++ problems

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. 

 

 

0 Kudos
Message 1 of 12
(4,234 Views)

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?

0 Kudos
Message 2 of 12
(4,197 Views)

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.

0 Kudos
Message 3 of 12
(4,194 Views)

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.

0 Kudos
Message 4 of 12
(4,163 Views)

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.

 

 

George Zou
0 Kudos
Message 5 of 12
(4,139 Views)

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

0 Kudos
Message 6 of 12
(4,128 Views)

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.

 

George Zou
0 Kudos
Message 7 of 12
(4,124 Views)

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 *. 

0 Kudos
Message 8 of 12
(4,098 Views)

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);

......

}

George Zou
0 Kudos
Message 9 of 12
(4,084 Views)

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.

0 Kudos
Message 10 of 12
(4,083 Views)