Which DLL gets loaded first?

Just starting out? Need help? Post your questions and find answers here.
User avatar
blueb
Addict
Addict
Posts: 1044
Joined: Sat Apr 26, 2003 2:15 pm
Location: Cuernavaca, Mexico

Which DLL gets loaded first?

Post by blueb »

I am including "libmariadb.dll" with my program.

Since users may have an older version of MariaDB installed on their machines, would:

Code: Select all

str.s = GetCurrentDirectory() + "libmariadb.dll"
UseMySQLDatabase(str)
force the User's machine to use MY version of "libmariadb.dll" and not the one in their system? :?:
- It was too lonely at the top.

System : PB 6.10 LTS (x64) and Win Pro 11 (x64)
Hardware: AMD Ryzen 9 5900X w/64 gigs Ram, AMD RX 6950 XT Graphics w/16gigs Mem
User avatar
Mijikai
Addict
Addict
Posts: 1360
Joined: Sun Sep 11, 2016 2:17 pm

Re: Which DLL gets loaded first?

Post by Mijikai »

The directory from which the application loaded is searched first.

msdn:
Standard Search Order for Desktop Applications:
1.The directory from which the application loaded.
2.The system directory. Use the GetSystemDirectory function to get the path of this directory.
3.The 16-bit system directory. There is no function that obtains the path of this directory, but it is searched.
4.The Windows directory. Use the GetWindowsDirectory function to get the path of this directory.
5.The current directory.
6.The directories that are listed in the PATH environment variable.
User avatar
blueb
Addict
Addict
Posts: 1044
Joined: Sat Apr 26, 2003 2:15 pm
Location: Cuernavaca, Mexico

Re: Which DLL gets loaded first?

Post by blueb »

The reason I ask is because I spotted the following in the Help files...
Result = OpenLibrary(#Library, Filename$)
Filename$: "The filename of the library to load. If the filename does not include a path, then the operating system will search for the library in its system folders, the applications directory and the current directory".

Makes it sound like:
#1 - system folders
#2 - applications directory
#3 - current directory

And I was thinking if it grabs the systems folder first, my included DLL won't be loaded.

Thanks
- It was too lonely at the top.

System : PB 6.10 LTS (x64) and Win Pro 11 (x64)
Hardware: AMD Ryzen 9 5900X w/64 gigs Ram, AMD RX 6950 XT Graphics w/16gigs Mem
User avatar
skywalk
Addict
Addict
Posts: 4004
Joined: Wed Dec 23, 2009 10:14 pm
Location: Boston, MA

Re: Which DLL gets loaded first?

Post by skywalk »

Yes, it is better to explicitly define the path to your library.

Code: Select all

CompilerIf #SQLITE_USE_DLL  ;-! USE sqlite3.dll
  #SQLITE_DLL_FNPATH$ = "C:\MyDB\sqlite3.dll"
  ;#SQLITE_DLL_FNPATH$ = "C:\Program Files\DB Browser for SQLite\sqlite3.dll"
  ;#SQLITE_DLL_FNPATH$ = "C:\Program Files\DB Browser for SQLite\sqlcipher.dll"
  UseSQLiteDatabase(#SQLITE_DLL_FNPATH$)
CompilerElse
  #SQLITE_DLL_FNPATH$ = #Empty$
  ;BUG;UseSQLiteDatabase(#SQLITE_DLL_FNPATH$)
  UseSQLiteDatabase()
CompilerEndIf
The nice thing about standards is there are so many to choose from. ~ Andrew Tanenbaum
User avatar
mk-soft
Always Here
Always Here
Posts: 5409
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: Which DLL gets loaded first?

Post by mk-soft »

Put it in the same path as program

Code: Select all

program_path.s = GetPathPart(ProgramFilename())
libmariadb_path.s = program_path + "libmariadb.dll"
UseMySQLDatabase(libmariadb_path)
With macOS i use my tool MyAppData to copy the libraries into [APP]/Contents/Library

Code: Select all

Macro GetParentPath(Path)
  GetPathPart(RTrim(path, #PS$))
EndMacro

program_path.s = GetPathPart(ProgramFilename())
libmariadb_path.s = GetParentPath(program_path) + "Library/libmariadb.dylib"
Debug "Path = " + libmariadb_path

UseMySQLDatabase(libmariadb_path)
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
User avatar
blueb
Addict
Addict
Posts: 1044
Joined: Sat Apr 26, 2003 2:15 pm
Location: Cuernavaca, Mexico

Re: Which DLL gets loaded first?

Post by blueb »

Thanks Fellas... good advice.

I hate leaving things to chance!
- It was too lonely at the top.

System : PB 6.10 LTS (x64) and Win Pro 11 (x64)
Hardware: AMD Ryzen 9 5900X w/64 gigs Ram, AMD RX 6950 XT Graphics w/16gigs Mem
Post Reply