06-25-2019 07:28 PM
I am in the process of moving large projects into a Subversion repo.
Currently my code has calls such as
CopyFile(SourceFileName, TargetFileName);
where SourceFileName and Target File Name are of the form S:\Absolute\Path\To\A\File.extension.
I want to be able to get rid of absolute paths, so that it doesn't matter where my teammates decide to checkout my Repo to on their machines.
So ideally SourceFileName would be of the form ..\..\Relative\Path\To\File.extension
Does the LabWindows CopyFile function from the Utility Library (utility.h) support relative paths? If so, what are they relative to? The location of the .c file where I call them? The .prj file? The directory where the .exe will be run from?
Also for the LoadPanel (int parentPanelHandle, char filename[], int panelResourceID) function from the User Interface Library (userint.h) can I use a relative path for the filename parameter? And what is it relative to?
I know it works if filename is an C:\absolute\path\to\file.uir, and I have seen code where filename is simply "file.uir" (where does LabWindows look for this file?). Can I make the filename "..\..\Path\to\file.uir"? And again, what is this relative to?
Last, and most importantly, If I have included "file.uir" in the project tree (so that I can see it in the .prj file), then will labwindows know where to find it if I just use "file.uir" in my call to LoadPanel ?
A lot of questions, I know, but I would really appreciate any help! Thank you!
and
Solved! Go to Solution.
06-26-2019 01:47 AM
Good news for you!
CopyFile and LoadPanel both support relative path addressing. And it is relative to whatever is returned by GetProjectDir.
You don't need to add the UIR file(s) to the project to be able to load it with LoadPanel. If you give only a file name, then it is searched in the project directory. Otherwise an absolute or relative path is required.
Hope this helps,
06-26-2019 02:40 AM
First of all, the easy answer
As can be read in the help for the function,
If the name is a simple filename that contains no directory path, the file is loaded from the directory that contains the executable.
From this assuption on more complex scenarios can be elaborated, for example a subfolder of the application directory where to store .UIR files or another folder. In both cases, you must embed the path both in the call to LoadPanel and in the #include for the .h file in this form:
Subfolder
#include "Subfolder\\Panels.h"
tmpH = LoadPanel (0, "Subfolder\\Panels.uir", PANEL);
A relative folder
#include "..\\Panels\\Panels.h"
tmpH = LoadPanel (0, "..\\Panels\\Panels.uir", PANEL);
(Note the double backslash needed to avoid C to consider '\P' as an escape character)
06-26-2019 12:46 PM - edited 06-26-2019 12:47 PM
Thank you for the response! After reading Roberto's answer I am looking at ebalci's again:
@ebalci wrote:
CopyFile and LoadPanel both support relative path addressing. And it is relative to whatever is returned by GetProjectDir.
Now I am confused. Roberto's response (and the documentation) says the paths are relative to the directory of the .exe. But GetProjectDir gives you where the .prj lives. Couldn't that be different from where the .exe lives?
So am I correct that if I make things relative to GetProjectDir (or use MakePathName and GetProjectDir to make my paths) it would not work if my .exe does not live in the same directory as my .prj?
Is my best course of action to tell my teammates they need to set their build configurations so that their .exe has the location relative to the .uir files that is expected by our source code?
Thanks
06-26-2019 01:03 PM
The term "project" is used in a loose sense in this function's name.
Here is the function description:
Gets the name of the directory that contains the currently loaded project file.
You can use GetProjectDir when you distribute a project and its related files to multiple users who might place the files in a different directory on each computer. If your program needs to access a file that is in the same directory as the project, you can use GetProjectDir and MakePathname to construct the full pathname.
In a stand-alone executable, the function obtains the directory containing the executable file.