No announcement yet.

A Declare statement Question

  • Filter
  • Time
  • Show
Clear All
new posts

  • A Declare statement Question

    I have a program that calls a dll that is not in the same
    directory as the program because the I have other programs
    using the same dll. The program doesn't know were the dll
    is but can find out because the file is up one directory and
    into the common files folder how can I do this?

    Note: I program just for fun so it doesn't really matter

  • #2
    Curtis, do as I would do, put a copy in each directory.

    Another just for Fun progammer, Jules


    • #3
      If xxx.Exe is located in MyDir, xxx.Dll in MyDir\MyDll, it possible to use
      Lib "MyDll\xxx.DLL"



      • #4
        Yes, you can use a relative path like "DLL\MYDLL.DLL" or "..\MYDLL.DLL"
        But they are relative to 'CURRENT DIR' not 'APPLICATION DIR'
        You cannot expect that current directory and application-path are equal
        in any cases, except those, where you explicit set them equal.
        That is: Your program is started via a shortcut, and you have set current dir.
        Loading DLL-s implicit (function in Lib "XXX.DLL" is declared) will take
        place before the EXE is loaded. That is YOU can not manipulate current
        directory in your program to make sure the path is correctly set.
        So the simple rule is: Never use hardcoded paths when referencing a DLL relative or not.
        Perhaps the user choose to run your app via an UNC-path....

        Explicit loaded DLL-s (LoadLibrary) is a different story.

        mailto:[email protected][email protected]</A>

        [This message has been edited by Fred Oxenby (edited July 20, 2000).]
        mailto:[email protected][email protected]</A>


        • #5
          relative to 'CURRENT DIR' not 'APPLICATION DIR'
          Fred --
          Do following
          Create a directory MyDir.
          Place here and compile MyExe.Bas
             #Compile Exe
             Declare Function Semen Lib "MyDll\MyDll.Dll" As Long
             Function PbMain
             End Function
          Create a subdirectory MyDll inside MyDir.
          Place and compile here MyDll.Bas
          #Compile Dll
          Function Semen Export As Long
             MsgBox CurDir$
          End Function
          Now time for test.
          Place it, where do you want.
          #Compile Exe
          Function PbMain
             Shell "\MyDir\MyExe.Exe"
          End Function



          • #6
            Well, Semen.
            At a first glance you seems to be right, but that is not entierly true...
            Please test this:
            Make a shortcut to your program. C:\MYDIR\MYEXE.DLL
            Set current directory to C:\WINDOWS
            Execute the shortcut. What happens?
            Open a Dosbox.
            Current directory = everything exept C:\MYDIR
            Start your program: C:\MYDIR\MYEXE.DLL

            mailto:[email protected][email protected]</A>

            mailto:[email protected][email protected]</A>


            • #7
              Under Win2000 all your suggestions works fine.
              There are reasons to think the same about NT4.
              About - 9x - no idea.
              If doesn't work, means that LoadLibrary (inside Pb prologue) works differently.

              PS. If doesn't work under 9x ... (I don't want to reboot)
              Note, that anyway if to start Exe from Explorer, Appdir = StartDir.
              Shortcuts could be (and should be) prepared by own your installation program.
              If you use Shell, you can change CurDir before it.


              [This message has been edited by Semen Matusovski (edited July 20, 2000).]


              • #8
                IIRC, WIndows programs will search for DLL files at run time in this order..

                1. Directory of the EXE
                2. Current Directory
                3. Windows directory (?? windows\system ??)
                4. PATH, in order.

                I know Windows does a search so I sure you can find the correct order.

                I just always store the DLLs used by any EXE in the same directory with the EXE and they all work fine.

                Michael Mattias
                Tal Systems (retired)
                Port Washington WI USA
                [email protected]


                • #9
                  Hi again Semen.
                  There are a lot of sublime problems when using relative paths.
                  It works the same on all platforms 98/NT4/W2000. As far as my testing goes.
                  If your program is run from a network you will se this kind of problem
                  more clearly. App-dir is on one (network)drive. Your current dir on a different
                  (local) drive etc..
                  All my apps are written for networks, so perhaps I am exaggerating this
                  In most circumstances it is safe to use paths relative to your application
                  I just wanted to alert you on traps I already felled in..

                  mailto:[email protected][email protected]</A>

                  mailto:[email protected][email protected]</A>


                  • #10
                    Thank you very much for all your help. It works great now all I
                    have to do is finish my program. Happy programming. Curtis