LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Issue with Loading Thorlabs Kinesis DLL in LabVIEW (Error Code 1386)

Hi folks,

 

I am experiencing an issue while trying to load the Thorlabs Kinesis DLL in LabVIEW. The DLL loads successfully when opened from the LabVIEW project, but I encounter a runtime error (Code 1386) when attempting to load it otherwise.

 

Sujith02_0-1729583728541.png

 

I have referred to several solutions provided by NI, such as creating a .NET configuration file and ensuring that the .NET DLLs are located parallel to the LabVIEW.exe folder, but none of these solutions have resolved the issue.

 

Upon deep diving into the dependencies of the DLL, I found that it relies on other Thorlabs DLLs. For example, I am working with Thorlabs.MotionControl.DeviceManagerCLI.dll. My implementation involves using these APIs as sub-VIs in other required VIs, and I have placed the DLLs in a folder parallel to the project. The below is the dependencies of Thorlabs.MotionControl.DeviceManagerCLI.dll.

 

Sujith02_1-1729583875902.png

 

The code implementation is I am having APIs with DLLs in it, and I am using these APIs as sub-VIs in another required VIs. I am also having the DLLs in a folder parallel to the project. The below is the screenshot of the Low-Level APIs.

 

Sujith02_2-1729583997557.png

Sujith02_3-1729584021125.png

Sujith02_4-1729584063995.png

 

Based on my observation, it seems that LabVIEW may not be able to locate the dependencies of the DLLs, preventing it from loading them correctly.

 

If anyone has insights or solutions regarding this issue, I would greatly appreciate your help. I’m eager to resolve this as soon as possible. I am also attaching the link from where I downloaded the DLLs Thorlabs - Photonics Products & Solutions.

 

Thank you!

Message 1 of 4
(2,286 Views)

I faced similiar issues with a different set of dlls. 

In my case I generated an EXE from the vis, and the dll was on a support folder. WHen running on Win 11 it got  an error.

Same thing, calling from a project, the source code worked, but the Exe would not find it. 

The workaround solution was to copy the dll into the same folder as the main application. 

try coping them on the same location as your main vi and see if works. 

 

Message 2 of 4
(2,254 Views)

I've been using Thorlabs DLLs for years.

 

My solution has been to use a class, not a library, and to add literally every DLL from the Thorlabs program files directory to the class. Yes, over 100 of them.  I also copied them all to be in the same folder as the class... they don't need to be called from Program Files.

 

Additionally, when I build them into an EXE, I change the location of the "data" folder.  Normally, and application's default is to put things in two folders:

 

C:\xxxxx\yyyyy\zzzzz\builds

C:\xxxxx\yyyyy\zzzzz\builds\data

 

Just change the "data" folder to be "C:\xxxxx\yyyyy\zzzzz\builds" as well.

 

Finally, in their older versions (but not now) there was an oddity where one of their DLLs was referencing a file that was internally a DLL, but did not have a DLL file extension.  I had to include that file as well.  I can't remember the file name, but if you look in the directory you get the DLLs from, if there's a file in there the EXACT same size as one of the DLLs, as well as being named the same as well as being named the same apart from the .DLL extension, then that may be an issue on their version.

0 Kudos
Message 3 of 4
(2,245 Views)

Hi all,

 

I encountered an issue with a LabVIEW-built executable where a Thorlabs DLL does not load when launching the EXE directly. Since I couldn’t find much information, I thought I would share it here as it might be useful for others.

 

Setup

LabVIEW application built into .exe
All DLLs (including Thorlabs and others) are initially placed in a data folder:

Application Folder
├── MyApp.exe
└── data\
├── Thorlabs.dll
├── OtherDLLs.dll

 

Understanding the Issue


From investigation, it appears that:

-LabVIEW can resolve DLLs that are directly referenced
-The Thorlabs DLL likely loads additional dependency DLLs internally
-These dependencies are loaded by name (not full path)
-Windows does not automatically search subfolders like .\data
-Therefore, dependent DLLs are not found unless the folder is part of the DLL search path

 

Workaround 1 — Batch File (Temporary Solution)

 

Keep your batch file name same as your executable name and place it next to executable.

 

@echo off
REM get the name of the bat, but removing the .bat
set "batname=%~n0"

REM build the exe full name
set "exename=%batname%.exe"

REM add ./data to the PATH variable
set "PATH=%CD%\data;%PATH%"

REM Lauch the app
start "" "%exename%"


Why this works:

-Adds the data folder to the process PATH
-Ensures Windows can find all Thorlabs-related DLLs and dependencies
-Requires launching through the batch file

 

Workaround 2 — Add data Folder to System Environment PATH (Permanent)


Add the full path of the data folder to Windows Environment Variables:

Variable name : Path
Variable Value: C:\Path\To\Application\data

 

Why this works:

Makes the DLLs discoverable globally
Allows running the EXE directly without batch file.

 

Workaround 3 — Place Thorlabs Kinesis DLLs Next to the EXE
Copy all required Thorlabs Kinesis DLLs and their dependencies from the data folder into the same directory as the executable:
Application Folder
├── MyApp.exe
├── Thorlabs.dll
├── ThorlabsDeviceManager.dll
├── ThorlabsMotionControl.dll
└── (other Kinesis DLLs)

 

Why this works:

Windows searches the application directory first when loading DLLs
Ensures both the main DLL and its dependencies are found without modifying PATH
Often the simplest deployment solution

 

Thank you,

Santosh

 

Message 4 of 4
(119 Views)