LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

GetDir versus FileSelectPopup

I am writing a DLL tool that is called from the application Zemax. The DLL needs to load data from a file. There is a default filename but not a default subdirectory. So: I get the working directory, add the default filename, and try to open the file. If this is not successfull, I use the FileSelectPopup for selecting the file/subdirectory.

Now the problem: the DLL is attached/detatched after each use. So I cannot remember (besides file or registry) the selected subdirectory. When I use GetDir, I always get the working directory of the the application Zemax. However on the second usage, the FileSelectPopup with parameter "" starts browsing in the previous used subdirectory.

 

Question: can I retrieve the subdirectory (and maybe even the previous file name) that is recently selected with FileSelectPopup, even while the DLL with all the code has been detached/attached ?

 

 

using labwindows/CVI 8.0

  Status = GetDir (PathName);
  if (displaybug) Cls();
  if (displaybug) printf("Current path is %s\n", PathName);
  MakePathname (PathName, "BeamZbf.zbf", FileName);
  if (displaybug) printf("Default file is %s\n", FileName);
  FilePtr = fopen(FileName, "rb");
  if (FilePtr==NULL)
  {
   Status = FileSelectPopup ("", "BeamZbf.zbf", "*.zbf",
           "Select ZBF with beam definition", VAL_LOAD_BUTTON, 0, 1, 1, 0, FileName);
   if (Status != VAL_EXISTING_FILE_SELECTED)
   {
          MessagePopup("BeamZbf-DLL", "Invalid file selected as user input");
    return(-1);
   }
   if (displaybug) printf("New selected file is %s\n", FileName);
   FilePtr = fopen(FileName, "rb");
  }

 

Regards, Jos

 

0 Kudos
Message 1 of 4
(3,494 Views)

If the dll is opened and closed, variables are not retained so your best solution may be to write it out to a static .ini file or use the registry to save the last selected path/file.

 

Note that GetDir retrieves the current working directory, which is not always the path of the application.  If say a file is double clicked that is associated with the application, then the working directory may end of being the place of that file.

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

Thanks for the reply.

 

I already noticed that the GetDir does not give me the 'memory' that I need. I even did not expect that it would. However as mentioned in the first post, the select box for file selection (FileSelectPopup) does keep track. Note that this cannot be the same working directory as GetDir because these give different results! Probably this is a Windows feature and probably the memory gets bad when I use other Windows explorer tools. But as a starter, this is typical the quick tool that I like to use.

 

So my question remains: where does FileSelectPopup start when the first input variable (for the default subdirectory) is "" ?

And also: is there a function/trick so that I can retrieve that subdirectory name ?

 

Regards, Jos

 

0 Kudos
Message 3 of 4
(3,445 Views)

It notes that it starts in the "Current Working Directory", however, if you open the File Select Popup, select a different directory, the next time you call FileSelectPopup, it will start from the last selected directory* whether you hit ok or cancel even though the "working directory" did not change.  I do not however, know where it saves this variable.

 

*If you ended at "My Computer" or another virtual location, I believe it goes back to the previous location and does not start from there.

 

Soo sorry if I didn't help you much as I probably just told you what you already know, but will have to have a CVI Insider answer the last question.

0 Kudos
Message 4 of 4
(3,441 Views)