OpenLibrary vs Import

Just starting out? Need help? Post your questions and find answers here.
coder14
Enthusiast
Enthusiast
Posts: 327
Joined: Tue Jun 21, 2011 10:39 am

OpenLibrary vs Import

Post by coder14 »

What is the difference or advantage between the two functions? I have both the lib and dll.

Also I asked this before but to reconfirm - is there any way to link libraries (lib, obj, dll) INTO the exe so that it will not need to be distributed? Some explanations on the net explain that static linking with an obj file means that the dll is not required at runtime - that the used functions are extracted and compiled into the exe. (not talking about including the dll in memory :| )

Is this correct and maybe only that PB is not able to link this way?

All explanations are welcome - great way to learn. :D
User avatar
ts-soft
Always Here
Always Here
Posts: 5756
Joined: Thu Jun 24, 2004 2:44 pm
Location: Berlin - Germany

Re: OpenLibrary vs Import

Post by ts-soft »

coder14 wrote:What is the difference or advantage between the two functions? I have both the lib and dll.
With lib you make a early-binding, with dll a late-binding (dynamically). The early-binding is faster, but gives immediately a
error, after start the exe, and won't start without the dll!
coder14 wrote:Is this correct and maybe only that PB is not able to link this way?
This is not correct, but the lib must be designed to not only wrap a dll. The depedency-libs have to link (Import) also.
PureBasic 5.73 | SpiderBasic 2.30 | Windows 10 Pro (x64) | Linux Mint 20.1 (x64)
Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.
Image
coder14
Enthusiast
Enthusiast
Posts: 327
Joined: Tue Jun 21, 2011 10:39 am

Re: OpenLibrary vs Import

Post by coder14 »

ts-soft wrote:
coder14 wrote:What is the difference or advantage between the two functions? I have both the lib and dll.
With lib you make a early-binding, with dll a late-binding (dynamically). The early-binding is faster, but gives immediately a
error, after start the exe, and won't start without the dll!
coder14 wrote:Is this correct and maybe only that PB is not able to link this way?
This is not correct, but the lib must be designed to not only wrap a dll. The depedency-libs have to link (Import) also.
Thank you ts-soft. I think I understand about the early and late bindings - something like constants and variables. So OpenLibrary is dynamic and Import is static, right?

But what do you mean the lib must be designed to not only wrap a dll? PB is not able to include the lib functions directly into the EXE right? In all cases the DLL is required right? :oops:
User avatar
ts-soft
Always Here
Always Here
Posts: 5756
Joined: Thu Jun 24, 2004 2:44 pm
Location: Berlin - Germany

Re: OpenLibrary vs Import

Post by ts-soft »

It gives different libs, mostly for dll like you can create with polib. This one can't used without DLL.
The other libs, a designed to use without dll (no dll created). This one you can also import, but you have to make sure,
all dependency (other libs, like runtimes) a solved.

SQLite is imported in PB or you can use MemoryModule.lib without DLL.

Code: Select all

CompilerIf #PB_Compiler_Processor = #PB_Processor_x64
  #MemoryModule_Lib$ = "MemoryModule64.lib"
CompilerElse
  #MemoryModule_Lib$ = "MemoryModule.lib" 
CompilerEndIf

Import #MemoryModule_Lib$
  MemoryLoadLibrary(*MemoryPointer)
  MemoryGetProcAddress(hModule, FunctionName.p-ascii)
  MemoryFreeLibrary(hModule)
  MemoryFindResource(hModule, lpName.p-ascii, lpType.p-ascii)
  MemoryFindResourceEx(hModule, lpName.p-ascii, lpType.p-ascii, wLanguage.w)
  MemoryLoadResource(hModule, hResInfo)
  MemoryLoadString(hModule, uID.l, *lpBuffer, nBufferMax.l)
  MemoryLoadStringEx(hModule, uID.l, *lpBuffer, nBufferMax.l, wLanguage.w)
  MemorySizeofResource(hModule, hResInfo)
EndImport
No dll required (only a DLL to use :wink: )
PureBasic 5.73 | SpiderBasic 2.30 | Windows 10 Pro (x64) | Linux Mint 20.1 (x64)
Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.
Image
coder14
Enthusiast
Enthusiast
Posts: 327
Joined: Tue Jun 21, 2011 10:39 am

Re: OpenLibrary vs Import

Post by coder14 »

ts-soft wrote:It gives different libs, mostly for dll like you can create with polib. This one can't used without DLL.
The other libs, a designed to use without dll (no dll created). This one you can also import, but you have to make sure,
all dependency (other libs, like runtimes) a solved.

SQLite is imported in PB or you can use MemoryModule.lib without DLL.

Code: Select all

CompilerIf #PB_Compiler_Processor = #PB_Processor_x64
  #MemoryModule_Lib$ = "MemoryModule64.lib"
CompilerElse
  #MemoryModule_Lib$ = "MemoryModule.lib" 
CompilerEndIf

Import #MemoryModule_Lib$
  MemoryLoadLibrary(*MemoryPointer)
  MemoryGetProcAddress(hModule, FunctionName.p-ascii)
  MemoryFreeLibrary(hModule)
  MemoryFindResource(hModule, lpName.p-ascii, lpType.p-ascii)
  MemoryFindResourceEx(hModule, lpName.p-ascii, lpType.p-ascii, wLanguage.w)
  MemoryLoadResource(hModule, hResInfo)
  MemoryLoadString(hModule, uID.l, *lpBuffer, nBufferMax.l)
  MemoryLoadStringEx(hModule, uID.l, *lpBuffer, nBufferMax.l, wLanguage.w)
  MemorySizeofResource(hModule, hResInfo)
EndImport
No dll required (only a DLL to use :wink: )
Thank you ts-soft. I think I understand now. :D
User avatar
jacdelad
Addict
Addict
Posts: 1477
Joined: Wed Feb 03, 2021 12:46 pm
Location: Planet Riesa
Contact:

Re: OpenLibrary vs Import

Post by jacdelad »

ts-soft wrote: Sun Jan 08, 2017 2:56 pm It gives different libs, mostly for dll like you can create with polib. This one can't used without DLL.
The other libs, a designed to use without dll (no dll created). This one you can also import, but you have to make sure,
all dependency (other libs, like runtimes) a solved.

SQLite is imported in PB or you can use MemoryModule.lib without DLL.

Code: Select all

CompilerIf #PB_Compiler_Processor = #PB_Processor_x64
  #MemoryModule_Lib$ = "MemoryModule64.lib"
CompilerElse
  #MemoryModule_Lib$ = "MemoryModule.lib" 
CompilerEndIf

Import #MemoryModule_Lib$
  MemoryLoadLibrary(*MemoryPointer)
  MemoryGetProcAddress(hModule, FunctionName.p-ascii)
  MemoryFreeLibrary(hModule)
  MemoryFindResource(hModule, lpName.p-ascii, lpType.p-ascii)
  MemoryFindResourceEx(hModule, lpName.p-ascii, lpType.p-ascii, wLanguage.w)
  MemoryLoadResource(hModule, hResInfo)
  MemoryLoadString(hModule, uID.l, *lpBuffer, nBufferMax.l)
  MemoryLoadStringEx(hModule, uID.l, *lpBuffer, nBufferMax.l, wLanguage.w)
  MemorySizeofResource(hModule, hResInfo)
EndImport
No dll required (only a DLL to use :wink: )
I know, I'm a bit late, but shouldn't the .l-datatypes be .i-datatypes?
PureBasic 6.04/XProfan X4a/Embarcadero RAD Studio 11/Perl 5.2/Python 3.10
Windows 11/Ryzen 5800X/32GB RAM/Radeon 7770 OC/3TB SSD/11TB HDD
Synology DS1821+/36GB RAM/130TB
Synology DS920+/20GB RAM/54TB
Synology DS916+ii/8GB RAM/12TB
User avatar
idle
Always Here
Always Here
Posts: 5095
Joined: Fri Sep 21, 2007 5:52 am
Location: New Zealand

Re: OpenLibrary vs Import

Post by idle »

probably not unless its a pointer, windows mostly uses ints for parameters so .l longs or short int .w/.u
User avatar
jacdelad
Addict
Addict
Posts: 1477
Joined: Wed Feb 03, 2021 12:46 pm
Location: Planet Riesa
Contact:

Re: OpenLibrary vs Import

Post by jacdelad »

Sorry for asking again, but isn't it possible that the address the pointer is pointing to is above MAXINT in a x64-system?
PureBasic 6.04/XProfan X4a/Embarcadero RAD Studio 11/Perl 5.2/Python 3.10
Windows 11/Ryzen 5800X/32GB RAM/Radeon 7770 OC/3TB SSD/11TB HDD
Synology DS1821+/36GB RAM/130TB
Synology DS920+/20GB RAM/54TB
Synology DS916+ii/8GB RAM/12TB
User avatar
idle
Always Here
Always Here
Posts: 5095
Joined: Fri Sep 21, 2007 5:52 am
Location: New Zealand

Re: OpenLibrary vs Import

Post by idle »

yes a pointer can of course point to a larger value, like values in XMM/YMM/ZMM registers 128/256/512
Post Reply