LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to call a DLL using a relative path

Solved!
Go to solution

Hello, I have made a VI, which needs to call the dynamic link library. At the beginning, I used the dynamic link library called by the absolute path, and the program can run perfectly. However, on another computer, the program will report an error, indicating that the library cannot be found. I tried to select the path in the block diagram, but also failed,Thank you very much for providing me with some ideas.

0 Kudos
Message 1 of 4
(142 Views)

The problem has been solved. It is the dynamic link library that I generated. Vs should be configured for static rather than dynamic generation. As shown in the picture below (sorry, my VS is in Chinese, but it does not affect the specific location of the setting ~)

0 Kudos
Message 2 of 4
(123 Views)
Solution
Accepted by topic author SliverAsh

Actually no, it hasn't been solved but circumvented.

 

The real problem is that you try to link with the debug version of the runtime library. You have legally no permission from Microsoft to distribute that so you may strictly speaking never distribute your DLL to anyone.

 

Technically the /MTd setting will link the debug version of the static C runtime library to your DLL. The /MDd setting will link with the dynamic C runtime library which can only be installed with the Visual Studio installer itself and you of course do not want to obligate your users to install Visual Studio on their system to run your DLL.

 

What you should do instead is to select /MD (which will require your users to install the Distributable C Runtime Library from Microsoft in the Version matching your Visual Studio installation, which you have the right to distribute with your DLL if you are a licensed Visual Studio user) or /MT, which will link the non-debug version of the C runtime library into your DLL, but still make it considerably larger that way.

 

Linking the static debug version of the C Runtime library is never meant to be used in production code. It makes your DLL not only much larger but also contains lots of extra runtime checks and suspenders and safety belts that makes your code run slower and can prompt the user with cryptic error messages if those checks encounter some weirdness. The non-debug version will simply crash on those weirdnesses but that should not be an issue since you of course debugged that DLL very thoroughly on many different computer systems, right? 😀

 

Even if you didn't, you do not want your users to have to report half page long error strings from runs of your DLL, that they definitely don't have any clue about and most casual C programmers neither. 😁

Rolf Kalbermatter
Averna BV
0 Kudos
Message 3 of 4
(111 Views)

Thank you very much for your detailed answer. As you said, I did encounter some problems with the libraries generated by MTd. I decided not to use MTd to generate libraries.

I also encountered some problems in the process of using MD to generate the library. I downloaded a WinPCAP-based dynamic link library sample file on NI, I put the download link at the bottom. My question is as follows: Dynamic link library can be successfully called in the downloaded sample folder. I get an error when I drag some of the sub-VIs from the file to a new folder showing that the dependency is broken. I'm wondering about this dependency, right? What exactly does this dependency mean? What do I do if I want to call this example from another folder?

https://forums.ni.com/t5/Example-Code/Ethernet-Packet-Sniffer-Utility-Using-WinPcap-Functions/ta-p/3... 

0 Kudos
Message 4 of 4
(97 Views)