Announcement

Collapse
No announcement yet.

A Declare statement Question

Collapse
X
 
  • 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
    Best regards
    Jules
    www.rpmarchildon.com

    Comment


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


      ------------------

      Comment


      • #4
        Semen,
        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.


        ------------------
        Fred
        mailto:[email protected][email protected]</A>
        http://www.oxenby.se



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

        Comment


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



          ------------------

          Comment


          • #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?
            Or
            Open a Dosbox.
            Current directory = everything exept C:\MYDIR
            Start your program: C:\MYDIR\MYEXE.DLL




            ------------------
            Fred
            mailto:[email protected][email protected]</A>
            http://www.oxenby.se

            Fred
            mailto:[email protected][email protected]</A>
            http://www.oxenby.se

            Comment


            • #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).]

              Comment


              • #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.

                MCM
                Michael Mattias
                Tal Systems Inc. (retired)
                Racine WI USA
                [email protected]
                http://www.talsystems.com

                Comment


                • #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
                  path.
                  I just wanted to alert you on traps I already felled in..


                  ------------------
                  Fred
                  mailto:[email protected][email protected]</A>
                  http://www.oxenby.se

                  Fred
                  mailto:[email protected][email protected]</A>
                  http://www.oxenby.se

                  Comment


                  • #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

                    Comment

                    Working...
                    X