zip32.dll & unzip32.dll

T

Terry Olsen

Has anyone written the classes to use the Info-Zip dll's in VB.Net 2003? I
took the VB6 examples from CodeGuru and attempted to convert it but I'm not
getting it.

For example, this line: tUser.lptrPrnt = AddressOf UnzipPrintCallback
Errors with: AddressOf' expression cannot be converted to 'Long' because
'Long' is not a delegate type.

So...i'm wondering if anyone has used these dll's in a VB.Net 2003 app
yet...

Thanks.
 
T

Tom Shelton

Has anyone written the classes to use the Info-Zip dll's in VB.Net 2003? I
took the VB6 examples from CodeGuru and attempted to convert it but I'm not
getting it.

For example, this line: tUser.lptrPrnt = AddressOf UnzipPrintCallback
Errors with: AddressOf' expression cannot be converted to 'Long' because
'Long' is not a delegate type.

So...i'm wondering if anyone has used these dll's in a VB.Net 2003 app
yet...

Thanks.

I've never used those. I usually just use the free
ICSharpCode.SharpZipLib.dll which can be had at
http://www.icsharpcode.net.

But, the reason you're having your problem calling this code is that
AddressOf does not work the same way as it did in VB.CLASSIC. In VB.NET it
returns a delegate - which is really a typesafe class wrapper around a
function pointer :) I'm unfamilar with this dll, but I'll give a little
mythical example...

'say the UnzipPrintCallback looked like this in VB.CLASSIC

Public Sub UnzipPrintCallback(ByVal handle As Long, ByVal data As String)
....
End Sub

In VB.NET this would be:
Private Sub UnzipPrintCallback (ByVal handle As IntPtr, _
ByVal data As String)

....
End Sub

We could pass this to our function like this

Class MyApplication

Private Delegate Sub UnzipPrintCallbackDelegate (ByVal handle As IntPtr, _
ByVal data As String)

Private Declare Ansi Sub SomeZipFunctionThatTakesTheCallback _
Lib "theZipLib.dll" (ByVal callback As UnzipPrintCallbackDelegate)

Private Sub UnzipPrintCallback (ByVal handle As IntPtr, _
ByVal data As String)

Console.WriteLine(data)
End Sub

Public Sub DoStuff()
' it is important that you keep a reference to any delegate
' you pass to unmanaged code. The reason is that, if gc runs
' the delegate will be collected out from under you and that
' can do nasty things to your application :)
Dim callback As New _
UnzipPrintCallbackDelegate (AddressOf Me.UnzipPrintCallback)

SomeZipFunctionThatTakesTheCallback (callback)
End Sub

Public Shared Sub Main()
Dim o As New MyApplication
o.DoStuff()
End Sub
End Class

Anyway, if you post more specifics, you'll get a more detailed answer :)
 
H

Herfried K. Wagner [MVP]

* "Terry Olsen said:
Has anyone written the classes to use the Info-Zip dll's in VB.Net 2003? I
took the VB6 examples from CodeGuru and attempted to convert it but I'm not
getting it.

For example, this line: tUser.lptrPrnt = AddressOf UnzipPrintCallback
Errors with: AddressOf' expression cannot be converted to 'Long' because
'Long' is not a delegate type.

So...i'm wondering if anyone has used these dll's in a VB.Net 2003 app
yet...

I don't have any experience with the DLLs you mention, but I assume the
declares are "buggy". Notice that there are other ways to provide ZIP
functionality:

<URL:http://www.icsharpcode.net/OpenSource/SharpZipLib/>

The VB.NET Resource Kit contains zipping functionality too:

<URL:http://msdn.microsoft.com/vbasic/vbrkit/>

It contains ComponentOne Zip for .NET:

<URL:http://www.componentone.com/products.aspx?ProductCode=1&ProductID=26>

Using J#'s zip functionality:

<URL:http://msdn.microsoft.com/msdnmag/issues/03/06/zipcompression/print.asp>
 
K

Ken Tucker [MVP]

Hi,

I would recommend using the SharpZipLib. But makes these change to the
zipuserfunctions structure if you still want to use info zip.

Public Delegate Function MyDllCommCallBack(ByRef s1 As CBChar) As
CBChar
Public Delegate Function MyDllPassCallBack(ByRef s1 As Byte, ByRef x
As Integer, _
ByRef s2 As Byte, ByRef s3 As Byte) As Integer
Public Delegate Function MyDllServCallBack(ByRef fname As CBChar, _
ByVal x As Integer) As Integer
Public Delegate Function MyDLLPrntCallBack(ByRef fname As CBChar, _
ByVal x As Integer) As Integer

Private Structure ZIPUSERFUNCTIONS
Dim DLLPrnt As MyDLLPrntCallBack
Dim DLLPASSWORD As MyDllPassCallBack
Dim DLLCOMMENT As MyDllCommCallBack
Dim DLLSERVICE As MyDllServCallBack
End Structure


Dim MYUSER As ZIPUSERFUNCTIONS
'UPGRADE_WARNING: Add a delegate for AddressOf DLLPrnt Click for
more:
'ms-help://MS.VSCC.2003/commoner/redir/redirect.htm?keyword="vbup1048"'
MYUSER.DLLPrnt = AddressOf DLLPrnt
'UPGRADE_WARNING: Add a delegate for AddressOf DllPass Click for
more:
'ms-help://MS.VSCC.2003/commoner/redir/redirect.htm?keyword="vbup1048"'
MYUSER.DLLPASSWORD = AddressOf DllPass
'UPGRADE_WARNING: Add a delegate for AddressOf DllComm Click for
more:
'ms-help://MS.VSCC.2003/commoner/redir/redirect.htm?keyword="vbup1048"'
MYUSER.DLLCOMMENT = AddressOf DllComm
MYUSER.DLLSERVICE = Nothing ' not coded yet :)

Ken
-----------------------
 
T

Terry Olsen

I've never used those. I usually just use the free
ICSharpCode.SharpZipLib.dll which can be had at
http://www.icsharpcode.net.

I've got my program unzipping now...usually the zip files contain 100 or so
small text or xml files. I'm using a buffer size of 2048. But it seems
pretty slow (compared to unzipping the same files with WinZip). Is there an
"optimum" buffer size or any other property that will speed this process up
a bit?

Also, is there an event or function that will give me a percentage
completed...say for using a progress bar?

Thanks.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top