LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Use Multiple DLL file in Lab view.

Solved!
Go to solution

Hello,

First time I am working in lab view. I need some guide line for learning lab view and some direction. we are manufacturing scientific device and which is control by our application. Our application is created in Qt and C++. Now we want to create the lab view application for controlling our device. 

which is good way to create the lab view application?
1) Is it good to create the lab-view code separately.  OR
2) Is it good to call .dll file from lab view.

      ( note: I am using our own code with Qt core library. So single function is calling           to multiple library)


if you agree with second option then:

 1) How can I load the multiple DLL for calling single function?

 2) Is it any way to load all DLL file once in project and use it multiple place?   

 

Sorry, if it is silly question.

Thank you.
  

 

Message 1 of 16
(4,692 Views)

 I would like to call function fun() from Labview.


Example:
I have two .dll Library.

DLL1.dll and DLL2.dll 

DLL1 contain function:

void fun(){
    fun1();
} 

 

DLL2 contain function:

void fun1(){
   
} 



 

0 Kudos
Message 2 of 16
(4,655 Views)

If you have only basic call to communication port, or TCP-IP etc..

It's better if you do 100% labview.

But it is also possible to call .dll in Labview.

 

I recommend you to use a .h (header file) to import your function. But if not possible, the call them manually.

look at the picture bellow:

image.png

Message 3 of 16
(4,641 Views)

Thank you bseguin for answer. From my research I found call dll library using "call  library function node". I need to define the definition of function in configuration. Inside the configuration we need to give the path for library.

So my main question is that, if calling function is call to another library function then do I need to give path for both libraries or only top level library?

 

Thank you.

0 Kudos
Message 4 of 16
(4,639 Views)

Only the top level library.

But make sure that the child library are at the same path. this will prevent issues.

But again, If you have a header file that defines your library function, use that file to import it in Labview. All your function will be imported in matter of minutes. If you code it, it will take many hours/days.

Benoit

Message 5 of 16
(4,631 Views)

Thank again bseguin. I happy to import all functions through share library facility but the problem is, definition of function contain complex data type and Qt tool data type. 
due it this reason, I need to use "call library function node". 

 

Thank you.

0 Kudos
Message 6 of 16
(4,627 Views)

You only specify the path to the DLL whose function you want to call directly. LabVIEW does not know that your DLL is calling other DLLs (well DLLs usually do but the caller NEVER EVER should be concerned about what a DLL does). A DLL should be always seen as a black box whose only known functionality is the documented API with its exported functions. Everything else should be completely irrelevant for the calling application since a DLLs internal implementation might change between versions and then your application suddenly doesn't work.

When LabVIEW requests from Windows to load your DLL, the Windows loader will see that this DLL has other dependencies and attempt to load them. And here Windows has a specific search order and unlike what bseguin recommended, putting your secondary DLL into the same directory as your main DLL will usually NOT work. It may work by accident as long as you are inside the LabVIEW IDE but even there it will sooner or later fail.

 

The locations Windows is looking for DLLs are following:

1) DLL is already loaded into the process by another dependency then it will just use that.

2) The directory from which the application loaded. (LabVIEW.exe in the IDE, yourapp.exe when you have a built application)

3) The <system> directory (System32 for 64 bit apps, SysWOW64 for 32 bit apps).

4) The <windows> directory

5) The current directory, a path Windows maintains per process and which is by default set to the directory from which the application was started but this can be changed by calling Windows API functions and is also updated by the Windows file dialog whenever it is dismissed with the OK button, to the directory it was in at that moment.

6) Any directory named in the PATH environment variable.

 

In the IDE when you use projects LabVIEW also makes Window add the directory to the search locations where the project file is loaded. So for development this is an options. Once you built your application you do want to put those secondary DLLs into the same directory as your executable, eventhough LabVIEW wants to put the DLLs that you call directory through the Call Library Node into a data subfolder. You can leave those DLLs in there as LabVIEW will tell Windows to load them from there but all the secondary DLLs that LabVIEW does not know about really need to be in the application folder itself so Windows can find them when LabVIEW requests the primary DLL to be loaded.

 

Exception to this rule is if the secondary DLL is something that gets normally installed on the system with its own installer, such as hardware drivers, or the runtime libraries for the compiler that was used to create the DLL. These are typically installed by its own installer into the system directory or into another private directory and then an entry in the PATH environment variable is added. Such DLLs you should normally not add to your application folder but instead add the Installer for those DLLs to your application installer, either explicitly by calling it from your installer or by documenting it in the installation procedure for your application.

Rolf Kalbermatter
My Blog
Message 7 of 16
(4,598 Views)

Thank you rolfk for answering to my question briefly. 
I think I call secondary dll according to your description.  Please correct me if I am in wrong direction. I tested with example code.

 

1)  generating MyDLL.dll.
main.h

#pragma once
void  __declspec(dllexport) pluse(double a, double b, double *f);
void  __declspec(dllexport) subtraction(double a, double b, double *f);
void  __declspec(dllexport) divide(double a, double b, double *f);
void  __declspec(dllexport) multiplication(double a, double b, double *f);

 

 

main.c

#include "main.h"
void pluse(double a , double b, double *f) {
	*f = a + b;
	return;
}

void subtraction(double a, double b, double *f) {
	*f = a - b;
	return;
}

void divide(double a, double b, double *f) {
	*f = a * b;
	return;
}

void multiplication(double a, double b, double *f) {
	*f = a / b;
	return;
}

2) with help of main.c and main.h file i generated MyDLL.dll file 
3) create MyDLL2.dll  with help of main.h, MyDLL.dll, source.h and source.c.
   
source.h

#pragma once
#include "main.h"
void  __declspec(dllexport) pluse1(double a, double b, double *f);
void  __declspec(dllexport) subtraction1(double a, double b, double *f);
void  __declspec(dllexport) divide1(double a, double b, double *f);
void  __declspec(dllexport) multiplication1(double a, double b, double *f);

source.c

#include "Source.h"
void  pluse1(double a, double b, double *f) {
	pluse(a, b, f);
	return;
}

void  subtraction1(double a, double b, double *f) {
	subtraction(a, b, f);
	return;
}

void  divide1(double a, double b, double *f) {
	divide(a, b, f);
	return;
}

void   multiplication1(double a, double b, double *f) {
	multiplication(a, b, f);
	return;
}

4) NOW I create the labview Project
5) Then Tool->Import->Shared Library.
6) select "Create Vis for Shared Library" and click on Next.
7) Give the path MyDLL2.dll and Source.h file, and click of Next.
😎 again click on Next.
9) again click on Next.
10) keep the library name as it is change the project library path, and Click next.
11)  Click Next
12) Click Next
13) Click Next

14) Click Finish
I got Project tree like below pic.


Capture.PNG

 

15) Copy the MyDLL.dll library file in to MyDLL2.lvlib project directory.
16) now I add MyDLL.dll in MyDLL2.dll library Project.
Capture.PNG

17) Save the Project.
18) Now My Project Tree is look like
Capture.PNG

19) Now If I will add the file MyDLL2.lvlib into another Project then I am able to use Vis (pluse1.vi, subtraction1.vi,multiplication1.vi,divide1.vi) in another project.

20) Use the MyDLL2.lvlib in another project. Directory is look like.
Capture.PNG

Creating exe file


Capture.PNG

and click  ok.
I got exe file in Directory

Capture.PNG

 

AND sub directory. 


Capture.PNG

So, My main Question is that. is it right way? or Is it create crash in future? 

 

0 Kudos
Message 8 of 16
(4,569 Views)

Nope!

 

MyDLL2.dll does not store any path information to MyDLL.dll, only the fact that the actual functions are exported by MyDLL.dll.

 

So when your LabVIEW executable tries to load MyDLL2.dll it asks Windows to load it. Windows will then see that MyDLL2.dll depends on MyDLL.dll and will look for it. Windows has ABSOLUTELY no knowledge of the data directory in your application. It does also NOT search dependencies in the same directory as the DLL that requires this dependency. The only location it searchs (besides the others explained earlier) is in the directory where the executable is located that started the current process, so in your case the directory where Application.exe is located.

 

To make sure Windows can find your MyDLL.dll you need to place it in the same directory as Application.exe. Personally I do place all the dlls for built applications in that directory when I have custom DLL dependencies but that is up to you. 

Rolf Kalbermatter
My Blog
Message 9 of 16
(4,560 Views)

Hi rolfk,

Thank you very much for supporting me. I understand about location of dll from your description. My Qt application is currently work by placing all dependent dll files in directory of .exe file. and it is completely work fine.


But I am missing something in lab-view application.

https://knowledge.ni.com/KnowledgeArticleDetails?id=kA00Z000000P81wSAC&l=en-US
Here they mention in "Additional information" point number 2.

  • Delete the WinAPI DLL from the data directory. The executable will now search for the DLL every time you launch the executable. Fix this by adding the <Windows>\System32 folder to the VI Search Paths (Tools»Options»Paths»VI Search Path) of the executable.

I deleted MyDLL.dll from data directory and put in to the Application.exe directory. I think I do not require to give the path environment variable from tool because from your description, if I will put the MyDLL.dll into Application.exe file location then Window will load the MyDLL.dll library. But my Labview Application is not working. It is show broken arrow. It is only work if I will put MyDLL.dll in to the data directory.

 

In addition, I tried another things. I create MyDLL2.lvlib Library project without myDLL.dll, and use my MyDLL2.dll library project in another project, But at that time I am unable to get build success. I things it is correct error, because without MyDLL.dll it should not build. 
 
which is steps miss by me?  Sorry for silly question.

 

0 Kudos
Message 10 of 16
(4,549 Views)