[Solved] OpenLibrary fails without DLL file extension

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
BarryG
Addict
Addict
Posts: 4128
Joined: Thu Apr 18, 2019 8:17 am

[Solved] OpenLibrary fails without DLL file extension

Post by BarryG »

Just got a bug report today from a customer who said a specific feature of my app was no longer working since my last update. After checking, I discovered OpenLibrary doesn't work with filenames that don't end with ".DLL", which seems a weird requirement. Would this be a Windows or PureBasic enforcement?

If it's a PureBasic thing, then I would like to request that it works with the file given to it, and not fail if that file doesn't specifically end in ".DLL", just like LoadImage will open a picture file that doesn't have an extension. Thanks!
Last edited by BarryG on Fri Feb 21, 2020 6:43 am, edited 1 time in total.
User avatar
Paul
PureBasic Expert
PureBasic Expert
Posts: 1282
Joined: Fri Apr 25, 2003 4:34 pm
Location: Canada
Contact:

Re: OpenLibrary fails without DLL file extension

Post by Paul »

Works fine here ;)
Maybe you have some other issue?

Compile this as DLL named "mydll.xxx"

Code: Select all

ProcedureDLL MyFunction()
  MessageRequester("Hello", "This is a PureBasic DLL !", 0)
EndProcedure

Run this code...

Code: Select all

If OpenLibrary(0, "mydll.xxx")
  CallFunction(0, "MyFunction")
  CloseLibrary(0)
EndIf
Image Image
BarryG
Addict
Addict
Posts: 4128
Joined: Thu Apr 18, 2019 8:17 am

Re: OpenLibrary fails without DLL file extension

Post by BarryG »

Paul, you're still using an extension, though. Rename your DLL to just "MyDLL" (no extension) and you'll see it doesn't work.
User avatar
Paul
PureBasic Expert
PureBasic Expert
Posts: 1282
Joined: Fri Apr 25, 2003 4:34 pm
Location: Canada
Contact:

Re: OpenLibrary fails without DLL file extension

Post by Paul »

LOL...
you said "OpenLibrary doesn't work with filenames that don't end with ".DLL"
You didn't say you wanted the DLL to have no extension at all ;)

So in that case, YES, OpenLibrary requires the file to have some type of extension.
Image Image
BarryG
Addict
Addict
Posts: 4128
Joined: Thu Apr 18, 2019 8:17 am

Re: OpenLibrary fails without DLL file extension

Post by BarryG »

True, but the question still remains: I wonder if this is a PureBasic requirement for OpenLibrary()? I have a bunch of support files without extensions, and this means I can't use the DLL at the moment, without showing it's a DLL due to the required extension. This in turn causes support issues because a few users run cleaning apps that delete "orphan" DLLs like that, because the DLL file alone in my directory and not loaded in memory all the time. So I need to stop those apps deleting it by mistake.

I'm hoping OpenLibrary() can be amended to act like LoadImage() and just read the specified file as presented.
User avatar
chi
Addict
Addict
Posts: 1087
Joined: Sat May 05, 2007 5:31 pm
Location: Austria

Re: OpenLibrary fails without DLL file extension

Post by chi »

LoadLibrary_(...) wrote:If the string specifies a module name without a path and the file name extension is omitted, the function appends the default library extension .dll to the module name. To prevent the function from appending .dll to the module name, include a trailing point character (.) in the module name string.
Et cetera is my worst enemy
BarryG
Addict
Addict
Posts: 4128
Joined: Thu Apr 18, 2019 8:17 am

Re: OpenLibrary fails without DLL file extension

Post by BarryG »

Thank you, chi - appending a single dot to the extensionless DLL filename does the job! And good to see it was a Windows thing and not PureBasic requirement. I can consider this request [Solved].
Post Reply