LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Compiled .exe only works if I allow it to prompt me for .dll files

Solved!
Go to solution

Hi,

 

My LabVIEW program uses several Call Library Function Nodes to call uEye_api.dll and uEye_LabVIEW.dll, which are libraries for working with IDS cameras. When I first compiled the program into an .exe it worked correctly, the only issue was that when I started the .exe it would prompt me to locate the .dll files, even though they were in the 'data' folder of the build. Once I located uEye_api.dll, the .exe would search the same location for uEye_LabVIEW.dll and automatically find it. The .exe would then work perfectly find and produce no errors.

 

I decided to build an installer that would copy the .dll's into the same folder as the .exe so that it would find them and not prompt the user as they ran the program. I ran the installer, the .dll's were copied into the .exe's directory, I started the .exe and it seemed to find the .dll's automatically. The issue then was that once the program reached the Call Library Function stage it returned an error, as if it couldn't find the .dll's any more.

 

Removing the .dll's from the .exe's directory and forcing the .exe to prompt me for the .dll's again, the Call Library Function Node started working. It seems as though the .exe can find the .dll's if they're in the same folder but the Library Function Nodes can only access them if they've had to be specified in a prompt at the beginning. 

 

Has anyone encountered this issue before? I've found a found a few .dll issues on the forum but not something that matches this. Any recommendations for things to try would be much appreciated.

 

Thanks,

Dan

0 Kudos
Message 1 of 6
(1,645 Views)
Solution
Accepted by topic author dml13

Windows DLL search path issue!

 

LabVIEW only can know about the DLLs that it directly calls. It places them in the data directory by default and adjusts the calling paths in the code to account for that.

 

Your uEye driver however consists of many secondary dependencies that you copied yourself into that folder too. Now what happens is this:

 

LabVEW requests from Windows to load A.DLL from .\data\a.dll. Windows tries to load the DLL and sees, aahh it needs also B.DLL. But it has no information where this B.DLL exists. So it starts a search at these locations:

 

1) already loaded in memory? use that!

2) inside the directory where the current processes exe file is located? load that!

3) inside C:\Windows\System32? load that!

4) inside C:\Windows? load that!

5) inside the current working directory? load that!

6) inside any directory listed in the PATH environment variable? load that!

7) sorry pal I can't load this DLL!

 

LabVIEW then prompts you to locate the DLL and you go into the data folder and select it.

But the Windows file dialog that LabVIEW uses has one insidous side effect when you browse to a file and select it with the OK button: it also updates the current directory to the directory this file is located in.

 

Now the whole chain of searches starts again, only now in step 5 above, Windows suddenly can find B.DLL that is located along A.DLL and bang, huge success!

 

The most simple solution is to update the Build specification for your executable to use for the Support directory the same location as your exe file. All DLLs are then copied into the application directory and Windows is totally happy as it can find your DLLs there according to step 2 in above search order.

 

The really correct solution would be if your driver was using a proper installer and put all its DLLs and other necessary support files in a commonly findable location itself.

 

Your runtime error would indicate that the DLLs somehow try to load some files (configurations files, plugin DLLs??) themselves using relative paths. The C runtime resolves such paths relative to the current directory, which unless you mess around with changing this, or selecting a file dialog, should be initialized at process startup to the same directory as where your executable is located. Most likely there are some other files than just DLLs that you need to place in the same folder too. But ultimately the uEye driver is badly flawed in that it makes to many assumptions.

Rolf Kalbermatter
My Blog
Message 2 of 6
(1,613 Views)

Hi Rolf,

 

Cheers for explaining how this works. I'll update the build specification support directory and have another test run.

 

Kind Regards,

Dan

0 Kudos
Message 3 of 6
(1,592 Views)

It looks like certain .dll's need to be installed in C:\Windows\System32\ and some need to be installed in the same location as the .exe file. The problem was that when I put all of the .dll's next to the .exe, the .exe would ignore the System32 location and this would cause the library function nodes to return errors. If I left certain .dll's out of the .exe directory, it would locate them in System32 properly and I only had to add the specific .dll's that were causing the .exe to prompt for their location to the .exe's directory.

 

I followed your advice and updated the build specification so that the support directory was the same folder as the .exe and so that uEye_LabVIEW.dll was included in the support directory but uEye_api.dll was left out (only located in system32). This has fixed the problem.

 

Thanks for your help Rolf!

Message 4 of 6
(1,558 Views)

The way you describe it it was your wanting to be smart that caused the problems. 😀

 

The existence of the uEye_api.dll in system32 would indicate that the uEye driver actually comes with a proper installer that places everything where it should be.

 

Of course the LabVIEW specific wrapper DLL is most likely not part of the official uEye driver installation and may even have been developed by an independant third party. In that case it should not hurt to leave this DLL in the default data directory that LabVIEW creates for a build. Most likely by not copying all the uEye driver DLLs into your LabVIEW build it should still work. Or maybe not, I have never looked at that driver so can't know for sure how it is built up. From what I have seen in some posts it seems to be a collection of several DLLs that each support different camera types and also support DLLs from third party libraries that the driver uses, including various GPL and other other open source libraries.

Rolf Kalbermatter
My Blog
0 Kudos
Message 5 of 6
(1,551 Views)

Hii dml13,

Thanks for the update and quick reply.  This works really well for us, thank you! AlaskasWorld PET

 

0 Kudos
Message 6 of 6
(1,507 Views)