ImportDLL

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
GPI
PureBasic Expert
PureBasic Expert
Posts: 1394
Joined: Fri Apr 25, 2003 6:41 pm

ImportDLL

Post by GPI »

Now:

Code: Select all

dll7zip=OpenLibrary(#PB_Any, "7-zip32.dll")
If dll7zip
  Prototype.l ProtoSevenZip(hWnd.l, szCmdLine.l, stOutput.l, dwSize.l = 0)
  Global SevenZip.ProtoSevenzip = GetFunction(dll7zip, "SevenZip")
  
  Prototype.l ProtoSevenZipCheckArchive(szFileName.p-ascii, iMode.l = 0)
  Global SevenZipCheckArchive.ProtoSevenZipCheckArchive = GetFunction(dll7zip, "SevenZipCheckArchive")
else
  debug "dll not found"
  end
endif
possible alternate:

Code: Select all

ImportDLL "7-zip32.dll
  SevenZip(hWnd.l, szCmdLine.l, stOutput.l, dwSize.l = 0)
  SevenZipCheckArchive(szFileName.p-ascii, iMode.l = 0)
ImportFail
  debug "Dll not found"
  end
ImportEnd
or

Code: Select all

ImportDLL "7-zip32.dll
  SZ(hWnd.l, szCmdLine.l, stOutput.l, dwSize.l = 0) as "SevenZip"
  SZCheckArchive(szFileName.p-ascii, iMode.l = 0) as "SevenZipCheckArchive"
ImportFail
  debug "Dll not found"
  end
ImportEnd
i Know, that a Import-Command exist, but when i don't have a .lib file, i can't use it.

btw. something like this:

Code: Select all

procedure sevenzipfail(hWnd.l, szCmdLine.l, stOutput.l, dwSize.l = 0)
  procedurereturn #false ; always return false, when dll doesn't exist
endprocedure
procedure sevenzipcheckarchivefail(szFileName.p-ascii, iMode.l = 0)
  procedurereturn #false
endprocedure

ImportDLL "7-zip32.dll"
  SZ(hWnd.l, szCmdLine.l, stOutput.l, dwSize.l = 0) as "SevenZip" onfail @sevenzipfail()
  SZCheckArchive(szFileName.p-ascii, iMode.l = 0) as "SevenZipCheckArchive" onfail @sevenzipcheckarchivefail()
ImportFail
  debug "Some function will not work without 7-zip.dll"
ImportEnd
would be nice.

when the import fails, it should use the given procedure instead. So the dll is optional for running the program.
Polo
Addict
Addict
Posts: 2422
Joined: Tue May 06, 2003 5:07 pm
Location: UK

Re: ImportDLL

Post by Polo »

You actually already can do this, on windows, if you have a provided .lib file with the DLL. However I pretty much agree with your request, it'd be handy on all platform to have a function like that!
GPI
PureBasic Expert
PureBasic Expert
Posts: 1394
Joined: Fri Apr 25, 2003 6:41 pm

Re: ImportDLL

Post by GPI »

GPI wrote:i Know, that a Import-Command exist, but when i don't have a .lib file, i can't use it.
:)

The second problem is, that the DLL isn't optional, when you use the import-command with a lib.
Polo
Addict
Addict
Posts: 2422
Joined: Tue May 06, 2003 5:07 pm
Location: UK

Re: ImportDLL

Post by Polo »

Oops sorry, I should stop reading quickly!! :)
jack
Addict
Addict
Posts: 1358
Joined: Fri Apr 25, 2003 11:10 pm

Re: ImportDLL

Post by jack »

hi GPI
you can make a lib file for a dll in PellesC, just type:
if 32-bit
polib yourdll.dll /machine:x86 /out:yourdll.lib
if 64-bit
polib yourdll.dll /machine:x64/out:yourdll.lib
User avatar
luis
Addict
Addict
Posts: 3895
Joined: Wed Aug 31, 2005 11:09 pm
Location: Italy

Re: ImportDLL

Post by luis »

jack wrote:hi GPI
you can make a lib file for a dll in PellesC, just type:
if 32-bit
polib yourdll.dll /machine:x86 /out:yourdll.lib
if 64-bit
polib yourdll.dll /machine:x64/out:yourdll.lib
I had some problems in the past doing that for 64 bit, then I solved in some way...

Maybe I did something wrong, not sure, but I saw the problem reported by other people too.

This is the thread if can be useful in some way: http://www.purebasic.fr/english/viewtop ... 65#p273865
"Have you tried turning it off and on again ?"
A little PureBasic review
Post Reply