Page 1 of 1

ImportDLL

Posted: Sat Oct 22, 2011 4:52 pm
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.

Re: ImportDLL

Posted: Sat Oct 22, 2011 6:29 pm
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!

Re: ImportDLL

Posted: Sat Oct 22, 2011 6:34 pm
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.

Re: ImportDLL

Posted: Sat Oct 22, 2011 6:58 pm
by Polo
Oops sorry, I should stop reading quickly!! :)

Re: ImportDLL

Posted: Sun Oct 23, 2011 1:09 am
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

Re: ImportDLL

Posted: Sun Oct 23, 2011 11:58 am
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