Page 1 of 1

Posted: Sun Oct 06, 2002 9:05 pm
by BackupUser
Restored from previous forum. Originally posted by SoulTaker.

Hi,

I want to convert my Visual Basic Zip and Unzip to PureBasic for all!

I know how to use the Win API's very well, just not sure how to use them in PureBasic.

1) How to call an Extern DLL not a Windows one.

2) How to use the Win API's in code.

In VB we had to Declare them first.

Would appricate any Examples that you could give me.

Thank you.

P.S.
Once converted i will give this code to the PureBasic Community.



Abit BD7-II Raid P4 1.9 gHz 384 Ram Xtasy GFroce 3 TI 200 CD-RW DirectX 9.0 Beta 2 Sound Blaster Live! XP Pro, Registered PureBasic version 3.30 For Windows.

Posted: Sun Oct 06, 2002 9:23 pm
by BackupUser
Restored from previous forum. Originally posted by blueb.

SoulTaker,

Here's an extremely simple example on how to use a DLL.

a:) the first file

Code: Select all

; -------------------
; The following is a procedure in
; a DLL (To create a DLL change compiler
; from menu to read: Shared DLL)
; it will create a file called PureBasic.dll

ProcedureDLL Addone(x.l)
x.l
ans.l
  Ans = x + 1
   ProcedureReturn Ans
EndProcedure

b) The second file

Code: Select all

; -------------------------------------
; This small program uses the above DLL
;
If OpenLibrary(0, "purebasic.dll")
  
  Result = CallFunction(0, "_Addone", 23456)
  MessageRequester("", StrF(result), 0)
  CloseLibrary(0)
EndIf

;Note: PureBasic.DLL is ALWAYS OVERWRITTEN !!!
;      If you wish to save it...
;      Find PureBasic.dll and rename it to AddOne.dll
; Hopeully will be fixed in version 3.40
Regards,
--blueb

Posted: Sun Oct 06, 2002 9:30 pm
by BackupUser
Restored from previous forum. Originally posted by blueb.

SoulTaker,
Notice in the example above:
to call a function in a DLL you have to
place an _ before the call (e.g. _AddOne)

Now...the opposite is true in a WinAPI call, see below.

Your next question
- How to use the Win API's in code.


Here's 2 API calls. You can call them directly
as shown (with the _ character after the procedure call)

Code: Select all

;Change to Source Directory
a$ = SourceDir$
If [b]SetCurrentDirectory[/b]_(@a$) = 0
  MessageRequester("Error","Can't find directory " + Chr(10) + Chr(13) + "Or doesn't exist! " + Chr(10) + Chr(13) + "Please re-type your choice",0)
  End
EndIf  

If [b]GetCurrentDirectory[/b]_( a$, @a$) = 0
  MessageRequester("Couldn't Establish a Current Directory",a$,0)
  End
EndIf

HTH,
--blueb

Posted: Sun Oct 06, 2002 9:38 pm
by BackupUser
Restored from previous forum. Originally posted by SoulTaker.

Here is one of the DLL Functions Declared in VB:

Private Declare Function ZpArchive Lib "zip32.dll" _
(ByVal argc As Long, ByVal funame As String, _
ByRef argv As ZIPnames) As Long '-- Real Zipping Action

argc.l
funame.s

argv as ZIPnames: is a user defined vb type as below.

'-- C Style argv
'-- Holds The Zip Archive Filenames
Public Type ZIPnames
zFiles(0 To 99) As String
End Type

I have been looking at the vb code and im sure that i can re-code this differentily in PureBasic.

So an example of how to call ZpArchive function from the zip32.dll is what im looking for, there are about 5 other functions in this dll that i will have to call.

Thank you


Abit BD7-II Raid P4 1.9 gHz 384 Ram Xtasy GFroce 3 TI 200 CD-RW DirectX 9.0 Beta 2 Sound Blaster Live! XP Pro, Registered PureBasic version 3.30 For Windows.

Posted: Sun Oct 06, 2002 11:06 pm
by BackupUser
Restored from previous forum. Originally posted by SoulTaker.

Ok BlueB i got it now i just have to open the DLL like i would a PureBasic DLL.

Thank you very much for your help.


Abit BD7-II Raid P4 1.9 gHz 384 Ram Xtasy GFroce 3 TI 200 CD-RW DirectX 9.0 Beta 2 Sound Blaster Live! XP Pro, Registered PureBasic version 3.30 For Windows.

Posted: Sun Oct 06, 2002 11:09 pm
by BackupUser
Restored from previous forum. Originally posted by El_Choni.

Using the example by Blueb, I think it would look like this in PB (place the code inside your ProcedureDLL):

Code: Select all

Dim zFiles.s(100)
If OpenLibrary(0, "zip32.dll")
  Result.l = CallFunction(0, "ZpArchive", argc.l, funame.s, @zFiles) ; I'm not sure about how to pass an array, but I think this is correct.
  MessageRequester("", Str(Result), 0)
  CloseLibrary(0)
EndIf
Try and tell us...

El_Choni

Posted: Sun Oct 06, 2002 11:20 pm
by BackupUser
Restored from previous forum. Originally posted by SoulTaker.

Thank you El_Choni,

I have a very lot to convert before i can even try to run this.

Also i will need to pass a callback address to these dll's, not really sure how to do this, but here is an example.

i think this is how i need to do it:

Procedure DLLMsg(param1.l, param2.l)

EndProcedure

DLLMsgPtr.l = *DLLMsg

Not sure if thats how to do it but i need to pass the address of the Procedure to the DLL Function.

This DLL Function calls this Procedure and others to send feed back to the application like the unzipping of files.




Abit BD7-II Raid P4 1.9 gHz 384 Ram Xtasy GFroce 3 TI 200 CD-RW DirectX 9.0 Beta 2 Sound Blaster Live! XP Pro, Registered PureBasic version 3.30 For Windows.

Posted: Sun Oct 06, 2002 11:27 pm
by BackupUser
Restored from previous forum. Originally posted by Pupil.
Originally posted by SoulTaker



Not sure if thats how to do it but i need to pass the address of the Procedure to the DLL Function.

This DLL Function calls this Procedure and others to send feed back to the application like the unzipping of files.
You can get the address of any procedure in your PB code by using the @ operator, like this:

Procedure test()
MessageRequester("test", "test", 0)
endprocedure

Address.l = @test()

Posted: Sun Oct 06, 2002 11:53 pm
by BackupUser
Restored from previous forum. Originally posted by SoulTaker.

Thank you Pupil,

So i would take this:

Procedure test()
MessageRequester("test", "test", 0)
endprocedure

Address.l = @test()

And then pass Address.l to the DLL Function for the CallBack Procedure correct?





Abit BD7-II Raid P4 1.9 gHz 384 Ram Xtasy GFroce 3 TI 200 CD-RW DirectX 9.0 Beta 2 Sound Blaster Live! XP Pro, Registered PureBasic version 3.30 For Windows.

Posted: Mon Oct 07, 2002 12:10 am
by BackupUser
Restored from previous forum. Originally posted by fred.

Yes.

Fred - AlphaSND