Smart lib Import ? or improved function check?
Posted: Sat Jan 02, 2010 10:39 am
Not sure how to explain this but let me use this example:
(Yeah I know, I left out the Protected SHGetFolderPath_.SHGetFolderPath_ from the "examples" below.)
but imagine if we could do this:
A lot cleaner and simpler right? It does exactly the same as the first code
IsFunction() would open the lib shell32.dll if not already open, check if the function exist, and if it does, returns true.
ImportS would import the lib and specified function but not try to load at start like Import or ImportC would,
the benefit would be that the program would start even if shell32.dll was not available,
and IsFunction() would return false for those functions obviously.
Fred, Freak, is it possible to do something like this or similar at all?
Or even something like
You know, just some way of simplifying this.
Myself I've begun to rely less and less on OS version etc. And instead just try to open the dll check if the function exist
and act on that instead, it's more future proof that way, and unlike Import you can inform the user if a dll or function that you need is missing more easily.
(Yeah I know, I left out the Protected SHGetFolderPath_.SHGetFolderPath_ from the "examples" below.)
Code: Select all
Prototype.i SHGetFolderPath_(hwndOwner.i,nFolder.l,hToken.i,dwFlags.l,*pszPath)
dll=OpenLibrary(#PB_Any,"shell32.dll")
If dll
SHGetFolderPath_=GetFunction(dll,"SHGetFolderPathW")
If SHGetFolderPath_
result=#True
EndIf
If result
;SHGetFolderPath available, let's do stuff using SHGetFolderPath() now.
EndIf
EndIf
Code: Select all
ImportS "shell32.lib"
SHGetFolderPath.i(hwndOwner.i,nFolder.l,hToken.i,dwFlags.l,*pszPath)
EndImport
If IsFunction(SHGetFolderPath())
;SHGetFolderPath available, let's do stuff now.
Else
;SHGetFolderPath not available, let's do it some other way now.
EndIf
IsFunction() would open the lib shell32.dll if not already open, check if the function exist, and if it does, returns true.
ImportS would import the lib and specified function but not try to load at start like Import or ImportC would,
the benefit would be that the program would start even if shell32.dll was not available,
and IsFunction() would return false for those functions obviously.
Fred, Freak, is it possible to do something like this or similar at all?
Or even something like
Code: Select all
Prototype.i SHGetFolderPath_(hwndOwner.i,nFolder.l,hToken.i,dwFlags.l,*pszPath)
If IsFunction("shell32.dll",SHGetFolderPath())
;SHGetFolderPath available, let's do stuff now.
Else
;SHGetFolderPath not available, let's do it some other way now.
EndIf
Myself I've begun to rely less and less on OS version etc. And instead just try to open the dll check if the function exist
and act on that instead, it's more future proof that way, and unlike Import you can inform the user if a dll or function that you need is missing more easily.