Announcement

Collapse
No announcement yet.

dll and using files - location open and keep opened

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • dll and using files - location open and keep opened

    i just written my first DLL program and i have some questions conerning files opened inside the DLL.

    also with Vista now, i have some questions that should be easily answered.
    i just tell you first what i am doing.
    i wrote a dll program to read the ip country database to service and exe program.

    so the exe calls the function in the dll, the dll then reads the data file then closes the file then everything is fine as long as all these programs are in the same folder.

    but what about when the exe program is not in the same folder or a cgi program that would do the same thing.

    i am looking for pointers(direction) on how to deal with data files and their locations when the dll is the program opening the data file.

    thanks in advance.
    paul
    p purvis

  • #2
    It makes no difference in which code module of a process a file is opened... it's open. If makes no difference what folder any file is in.. once it is opened, its path and name are fixed.

    There is, however, a restriction/limitation of the compiler that a PB file handle (hard coded #1 thru #something_big or obtained with FREEFILE) is valid only in the module in which the file was opened using that handle.

    As general rules for file handling I use..

    1. A file is CLOSEd in the same procedure in which it is OPENed. If additional procedures require that open file handle, it is passed as a parameter.
    2. All file names use fully-qualified names when opened.
    3. If you need to pass an open handle to another procedure, and that receiving procedure is located in a different code module, you pass the SYSTEM handle obtained using the FILEATTR() function to that module and use the OPEN HANDLE statement to access the file in that procedure.
    4. A disk file is never kept open whilst waiting for a user action.

    These rules have kept me out of trouble.
    Michael Mattias
    Tal Systems (retired)
    Port Washington WI USA
    [email protected]
    http://www.talsystems.com

    Comment


    • #3
      Agree mostly with Michael but for No 4, a FLUSH statement can be simpler, faster and just as effective. There are a number of advantages to opening and updating files in DLL's, particularly database types where the reusability of the DLL encourages much more robust code that gets tested in many different ways in different applications

      Comment

      Working...
      X