LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Create LabView dll library

Solved!
Go to solution

Helo, 

 

I would kindly ask you how can I create dll library from Labview 2016 (32-bit) which can be used in Python (for example). 

 

I create basic Vi which add two numbers (file add-dll.vi in the attachment).

I compile it from Project exploder > Build Specifications > New > Shared Library (DLL).

Compiled addLib.dll I can import to LW again and use as usual external library.

 

When I call addLib.dll in python(3.6.1 (v3.6.1:69c0db5, Mar 21 2017, 17:54:52) [MSC v.1900 32 bit (Intel)]

('32bit', 'WindowsPE') ) (source .py code + README fiel in attachment )

 

Thank you for any help you can provide.

 

Best regards 

Michal

Download All
0 Kudos
Message 1 of 7
(4,628 Views)
Solution
Accepted by topic author FaustDantes

You need to also define the function interface before you can call a function. That includes the return type of the function if it is not an int and the parameter list. If you don't define anything, Python ctypes will assume that everything needs to be int's and that will both confuse the DLL when trying to retrieve the parameters from the stack as well as Python when trying to interpret the return value of the function.

  

dl.addXY.restype = ctypes.c_double
dl.addXY.argtypes = [ctypes.c_double, ctypes.c_double]

 

Rolf Kalbermatter
My Blog
0 Kudos
Message 2 of 7
(4,612 Views)

Thank you very very very very much.  Your answer helps me a lot.

 

Best regards 

Michal

0 Kudos
Message 3 of 7
(4,601 Views)

I would kindly ask you which c data type can be used in that function from LabView .dll function

int32_t __stdcall myIncrement(int32_t X);  

 

If I use c data type "ctypes.c_int32"

dl.myIncrement.restype = ctypes.c_int32
dl.myIncrement.argtypes = [ctypes.c_int32]
 compiler show message 

Procedure called with not enough arguments (4 bytes missing) or wrong calling convention.

 

Which data type should be suitable for this function? 

 

 

0 Kudos
Message 4 of 7
(4,585 Views)
Solution
Accepted by topic author FaustDantes

When your functions uses stdcall convention you need to change the LoadLibrary() call to:

 

dl = ctypes.windll.LoadLibrary(dlURL)
Rolf Kalbermatter
My Blog
0 Kudos
Message 5 of 7
(4,579 Views)

Hi, I have a similar problem. I need to import a dll created in LabView 2016 64bit in c++.

I do not have experience in c++ and I was wandering whether there is any documents or white paper that describes how to do. I made a dummy dll, with basic function just to test the call in c++.

Here below the prototypes of the dll:

 

int32_t FOI_Test_Algo(char SettingFilePath[], double imgArray[], int32_t Action, char OutputString[], int32_t lenOutputString, int32_t lenImgArray);

 

I saw in your file that you declared your function  and the LVDLL in the .h. Should I do the same?

 

In the source code, do I have to load the dll as you did in "dl = ctypes.cdll.LoadLibrary(dlURL)" before using it?

 

Thank you very much for your support.
 
 

 

0 Kudos
Message 6 of 7
(4,029 Views)

This was for Python, not C++. If you use Visual C or similar you really should know how to link to a DLL. If you don't you should first study the principles of DLL operation.

 

There is absolutely nothing magic about calling a LabVIEW DLL in comparison to calling any other DLL. When you get a LabVIEW DLL you also get two other files, one with the ending .lib and another with the ending .h. You #include the .h in your source code file and link your project with the .lib file, and you are done. Of course the bitness of the DLL needs to be the same as the bitness of the appilcation you want to create. And you need to make sure that on every target machine you want to run your program on, you also install the LabVIEW runtime engine with the same version than the LabVIEW version you created your DLL with.

 

 

Rolf Kalbermatter
My Blog
0 Kudos
Message 7 of 7
(4,023 Views)