LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

current working directory

hi All,

I want to find the current working directory of my LabVIEW exe when it is called from VC++.

My application requires that I must look for a specific info file in the form of .ini or .txt.......

The problem is VC++ people say that I should look for that file wherever the full application is running, meanig that the one done in VC & installed in any of the drives C.D.E. or F whatever it may be. They say that as per Windows, there is only one current working directory.

What I saw in LabVIEW is we've to specify the entire path for a file to look for or atleast the path preceding the exact file. I think I m right.

You guys help me out reg this. Its urgent.

Regards,

Partha.

- Partha ( CLD until Oct 2027 🙂 )
Message 1 of 11
(10,927 Views)

I'm not sure I understand, but to find the directory where you ran your exe, you need to use a property node and get the Application>>Directory Path property.

If you need this data in the C++ application, you should set your LV EXE to have its ActiveX interface active and then you should be able to get this property from the C++ app through ActiveX.


___________________
Try to take over the world!
0 Kudos
Message 2 of 11
(10,919 Views)

hi tst, what U told actually gives the normal installation directory info of LabVIEW, ie, C:\Program Files\National Instruments\LabVIEW7.1

But what I want is can I find a particular file from LabVIEW in the location where the entire application developed in VC++ is running.

pls clarify me reg this.

Partha.

- Partha ( CLD until Oct 2027 🙂 )
Message 3 of 11
(10,915 Views)

The property does not return the LV directory, but the directory for the application. Since you're inside LV, the application is LabVIEW.exe and that's why you see that directory. In an EXE, you will get the directory for the EXE. Attached is another example for how to find the directory where a VI exists (modified from OpenG code).

I still don't understand which path you are looking for and where you are going to use it, so if this doesn't help, you should explain that again.


___________________
Try to take over the world!
Message 4 of 11
(10,911 Views)

hi tst, thanx first for Ur help but Ur VI is broken bcos subVIs are not there. I m using LV7.1.

what I told was the VC++ people will supply me with a ini file that contains details about various PIN choice selected by the user during Setting Parameters at the beginning of the appl, ie, while in VC++. they ll call me to execute DMM using PXI1042.

what I want to do now is to read that .ini file from the hierarchy of the various steps configured by the user at the startup , & read it to take the details in it & pass rhem into my VI & do the calculation for hardware & then run the DMM part.

...hhhhhhh, very long line indeed, giving space to breathe.

Now please tell me how I ll go & look for that .ini file in the hierarchy which had got placed from VC++ in the path where it was installed, say C: or 😧 or whatever it may be.....

they tell me that there is option in VC++ to do like that means , if U specify the filename alone, it is enough to look for that in the installed directory's hierarchial step.

i tell them it is not that much easy to like that in LV, bcos I ve not seen an icon in LV,s Function palette which ll give U the "Current Working Directory" like the case if Current VI's path or so.

please help me with a solution, my time is running out.

anyway r hat was beter than this icon.

Regards,

Partha.

- Partha ( CLD until Oct 2027 🙂 )
Message 5 of 11
(10,908 Views)
If I correctly unserstand, you want to retrieve the current Windows directory as returned by the Windows API function GetCurrentDirectory.
The attached vi should do the trick. Please note that the directory name length should not exceed 255.
I hope this helps you.

Paolo
Paolo
-------------------
LV 7.1, 2011, 2017, 2019, 2021
Message 6 of 11
(10,895 Views)

OK. Let's see if I understand correctly. You have a C++ app which writes to an INI file. Then, that app calls a LV EXE and you want that EXE to read the INI file, right?

In that case, the simplest way would probably be to tell the C++ to add a command line switch to your LV EXE which will point to the INI file (let's say your application is foo.exe, then they should call "foo.exe d:\foo\bar.ini). You can read command line arguments with one of the Application class properties (it's probably called Command Line Arguments, but I can't check). Other methods of communication between C++ and LV apps include VI server through ActiveX, DLLs and TCP, but they will all be more complex. Another option is for you to decide on an agreed location which will hold a file which will have the path to the INI file in it, but that's not a very robust solution and ultimately not recommended.

If you place the EXE in the same directory as the C++ EXE then you can just use the example I showed earlier. Go to the site I linked to and download the commander. Then you can use the commander to download the packages and if you download the file package you will also get a VI which will return the current VI's directory. It basically uses the technique shown in the VI I attached (it keeps stripping the path until it gets to a directory), so you can just do that yourself as well. 


___________________
Try to take over the world!
Message 7 of 11
(10,886 Views)

hi tst & pincpanter,

thanks for Ur reply, thats what I was exactly looking for.

pinc,can U put the VI generate tring buffer.vi? it s showing broken arrow.

sorry for bothering U on Sat too.

tst, many thanks for Ur detailed explanation.

Regards,

Parthasarathi.

Qmax Test Equipments, Chennai, India.

- Partha ( CLD until Oct 2027 🙂 )
Message 8 of 11
(10,868 Views)


@pincpanter wrote:
If I correctly unserstand, you want to retrieve the current Windows directory as returned by the Windows API function GetCurrentDirectory.
The attached vi should do the trick. Please note that the directory name length should not exceed 255.
I hope this helps you.

Paolo


Windows maintains a current directory per application instance. So reading the current directory in a LabVIEW program wil most likely give you a completely different directory location than what the VC++ application saw when it had executed.
Also there are various operations in Windows such as the file dialog that will ALWAYS update the current directory when the dialog is dismissed with OK.

So you really will have to tell your LabVEW application where your C application thinks the current directory path was, as they will both see likely different current directories except maybe at the very start of both applications. Otherwise if your C++ application is rather a DLL you call from LabVIEW through the Call Library Node it will run in the application space of LabVIEW and inherit the current directory setting of the LabVIEW process and then you could actually rely on the Windows current directory as long as you make sure that no File Dialog is presented (and possibly some other Windows API calls that might be hard to control but LabVIEW at least shouldn't change the current directory on its own) between the time your DLL function used the current directory and the time you retrieve this setting in LabVIEW.

The whole conept of current directory however is really something only really useful inside a single command line application, since various dialogs and components in Windows can influence that setting and different processes get their own current directory setting.

Rolf Kalbermatter
Rolf Kalbermatter  My Blog
DEMO, Electronic and Mechanical Support department, room 36.LB00.390
Message 9 of 11
(10,860 Views)
Rolf,
what you say is true, but... I simply assumed that "VC++ people" know what they're asking for. If the LV program is launched as a child process by the C++ application, the INITIAL current directory should be the same. I guess that what the LV should do with this directory is only to search and read the ini file in and then forget it.

Now, to come back to Partha's problem, here is the missing vi (sorry I forgot it).

Paolo
Paolo
-------------------
LV 7.1, 2011, 2017, 2019, 2021
0 Kudos
Message 10 of 11
(10,819 Views)