Results 1 to 26 of 26

Thread: [RESOLVED] Using embedded DLL's/Extracting .ZIP's

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Jun 2010
    Posts
    23

    Resolved [RESOLVED] Using embedded DLL's/Extracting .ZIP's

    Hi all, another few questions.

    I am using DotNetZip for use of extracting a .ZIP from the resources. When I run the standalone .EXE, errors appear about a missing DLL, so I added it into the resources via the properties panel, but I still get the same error. How do I use the embedded .DLL?

    Another question, might be the wrong place to ask it but I am having problems extracting 'Conroy.zip' from my resources using DotNetZip. If anyone could show me the code or give advice, it would be greatly appreciated.

    Thanks,

    -Conroy.

  2. #2

    Re: Using embedded DLL's/Extracting .ZIP's

    Are you copying the DotNetZip DLL file to the same directory as your exe?

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Jun 2010
    Posts
    23

    Re: Using embedded DLL's/Extracting .ZIP's

    Quote Originally Posted by formlesstree4 View Post
    Are you copying the DotNetZip DLL file to the same directory as your exe?
    Yes, at the moment I am, and it works fine, but I want to send this program to other people as a standalone .EXE, hence why I am wondering how to use it as an embedded resource.

    Thanks,

    -Conroy

  4. #4

    Re: Using embedded DLL's/Extracting .ZIP's

    You would still have to have it present. Visual Basic isn't going to read the EXE to find the DLL, it's going to want it either in the GAC or right next to the EXE.

  5. #5

    Thread Starter
    Junior Member
    Join Date
    Jun 2010
    Posts
    23

    Re: Using embedded DLL's/Extracting .ZIP's

    Alright, I will put it in the same folder when I give it out to people.

    What about the DotNetZip, anyone have any knowledge of that? I thought I might ask that while I'm here. If not, I'll go onto their website and ask.

    Thanks,

    -Conroy

  6. #6
    PowerPoster JuggaloBrotha's Avatar
    Join Date
    Sep 2005
    Location
    Lansing, MI; USA
    Posts
    4,286

    Re: Using embedded DLL's/Extracting .ZIP's

    I'm not familiar with DotNetZip but I do know about reading resources out of your app using a memory stream and I doubt you can pass a memory stream to DotNetZip, which if true means you'd need to extract the zip file to the user's temp folder (you can delete it when done extracting from it) then pass the file path to the DotNetZip extract method and go from there.
    Currently using VS 2015 Enterprise on Win10 Enterprise x64.

    CodeBank: All ThreadsColors ComboBoxFading & Gradient FormMoveItemListBox/MoveItemListViewMultilineListBoxMenuButtonToolStripCheckBoxStart with Windows

  7. #7

    Thread Starter
    Junior Member
    Join Date
    Jun 2010
    Posts
    23

    Re: Using embedded DLL's/Extracting .ZIP's

    Quote Originally Posted by JuggaloBrotha View Post
    I'm not familiar with DotNetZip but I do know about reading resources out of your app using a memory stream and I doubt you can pass a memory stream to DotNetZip, which if true means you'd need to extract the zip file to the user's temp folder (you can delete it when done extracting from it) then pass the file path to the DotNetZip extract method and go from there.
    Yes, I was thinking about doing that. Thanks for the reply.

    I wont 'resolve' the thread yet, I might need further assistance.

    Thanks again,

    -Conroy

  8. #8
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: Using embedded DLL's/Extracting .ZIP's

    If DotNetZip doesn't accept memory streams, that's pretty lame. I use SharpZipLib, all it wants is a stream.. doesn't care if it's a memory stream, file stream or what, as long as it is a stream. In fact, my use of it makes heavy use of memory streams, zipping and unzipping the data.

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  9. #9

    Thread Starter
    Junior Member
    Join Date
    Jun 2010
    Posts
    23

    Re: Using embedded DLL's/Extracting .ZIP's

    Does the library support zipping to a stream? Or unzipping from a stream?
    Yes, you can zip up files and Save the zip archive to a stream. As well you can Read a zip archive from an open stream - I use this for embedded resources in apps: I call GetManifestResourceStream(), and then unzip that resource. Reading and writing streams complements the capability of being able to Save to a plain file or read from a plain file. The Save-to-a-stream capability allows you to write a zip archive out to, for example, the ASP.NET Response.Output stream, without creating an intermediate file. Very nice for ASP.NET applications.
    I just found out it does support Stream, but I am unsure how to do it. It sounds complicated and I find it easier just moving the .ZIP to a temp folder. On the other hand, if you would like to show me how Stream, be my guest.

    Thanks,

    -Conroy

  10. #10
    PowerPoster JuggaloBrotha's Avatar
    Join Date
    Sep 2005
    Location
    Lansing, MI; USA
    Posts
    4,286

    Re: Using embedded DLL's/Extracting .ZIP's

    Ok, so when you use the memory stream to extract the file from the resources instead of passing it to a FileStream (to write it to the hard drive) pass it to the dll for extraction.
    Currently using VS 2015 Enterprise on Win10 Enterprise x64.

    CodeBank: All ThreadsColors ComboBoxFading & Gradient FormMoveItemListBox/MoveItemListViewMultilineListBoxMenuButtonToolStripCheckBoxStart with Windows

  11. #11

    Thread Starter
    Junior Member
    Join Date
    Jun 2010
    Posts
    23

    Re: Using embedded DLL's/Extracting .ZIP's

    Quote Originally Posted by JuggaloBrotha View Post
    Ok, so when you use the memory stream to extract the file from the resources instead of passing it to a FileStream (to write it to the hard drive) pass it to the dll for extraction.
    Could you show me an example? The .ZIP is named 'Conroy.zip'.

  12. #12

    Re: Using embedded DLL's/Extracting .ZIP's

    Take a look at FileStreams at MSDN.

  13. #13

    Thread Starter
    Junior Member
    Join Date
    Jun 2010
    Posts
    23

    Re: Using embedded DLL's/Extracting .ZIP's

    Code:
    Dim fs As FileStream = Me.GetType().Assembly.GetManifestResourceStream("Conroy.zip")
    Using zip1 As ZipFile = ZipFile.Read(fs)
    Returns null, any ideas?

  14. #14
    PowerPoster JuggaloBrotha's Avatar
    Join Date
    Sep 2005
    Location
    Lansing, MI; USA
    Posts
    4,286

    Re: Using embedded DLL's/Extracting .ZIP's

    Something like this:
    Code:
    Using s As Stream = Me.GetType().Assembly.GetManifestResourceStream(Me.GetType(), "Conroy.zip")
    
    'Pass "s" to the zip dll thing
    
    End Using
    Currently using VS 2015 Enterprise on Win10 Enterprise x64.

    CodeBank: All ThreadsColors ComboBoxFading & Gradient FormMoveItemListBox/MoveItemListViewMultilineListBoxMenuButtonToolStripCheckBoxStart with Windows

  15. #15

    Thread Starter
    Junior Member
    Join Date
    Jun 2010
    Posts
    23

    Re: Using embedded DLL's/Extracting .ZIP's

    I appreciate your help.

    Code:
    Using s As Stream = Me.GetType().Assembly.GetManifestResourceStream(Me.GetType(), "Conroy.zip")
    For Each File In s
    File.Extract("C:\Users\Dale\Desktop", ExtractExistingFileAction.OverwriteSilently)
    Next
    End Using
    Error 1: Expression is of type 'System.IO.Stream', which is not a collection type.

  16. #16
    PowerPoster JuggaloBrotha's Avatar
    Join Date
    Sep 2005
    Location
    Lansing, MI; USA
    Posts
    4,286

    Re: Using embedded DLL's/Extracting .ZIP's

    s is the stream itself, you pass the stream to the dll and let the dll extract the files from the zip file.
    Currently using VS 2015 Enterprise on Win10 Enterprise x64.

    CodeBank: All ThreadsColors ComboBoxFading & Gradient FormMoveItemListBox/MoveItemListViewMultilineListBoxMenuButtonToolStripCheckBoxStart with Windows

  17. #17

    Thread Starter
    Junior Member
    Join Date
    Jun 2010
    Posts
    23

    Re: Using embedded DLL's/Extracting .ZIP's

    Could you show me another example, please? Sorry to bother you, I just don't understand it.

    Thanks,

    -Conroy.

  18. #18
    Fanatic Member Emcrank's Avatar
    Join Date
    Jan 2009
    Posts
    566

    Re: Using embedded DLL's/Extracting .ZIP's

    If you dont want to use 3rd party .ZIP tools, you can use the built in to windows, shell32.dll
    check out the link in my signature about Extracting/Zipping using shell32

    PS: its so much easier.

  19. #19

    Thread Starter
    Junior Member
    Join Date
    Jun 2010
    Posts
    23

    Re: Using embedded DLL's/Extracting .ZIP's

    I know how to extract zip's on my hard drive, so that's not a problem, it's just using them from my resources which confuses me.

    -Conroy

  20. #20
    PowerPoster JuggaloBrotha's Avatar
    Join Date
    Sep 2005
    Location
    Lansing, MI; USA
    Posts
    4,286

    Re: Using embedded DLL's/Extracting .ZIP's

    conroy, without me having the dll here to work with, I can't really provide any more info than I already have. Besides if you follow what's been said in this thread, it shouldn't be very difficult to pass the stream to the unzipping function (which you say it supports) and I've shown how to get the stream, so just pass it in.
    Currently using VS 2015 Enterprise on Win10 Enterprise x64.

    CodeBank: All ThreadsColors ComboBoxFading & Gradient FormMoveItemListBox/MoveItemListViewMultilineListBoxMenuButtonToolStripCheckBoxStart with Windows

  21. #21

    Thread Starter
    Junior Member
    Join Date
    Jun 2010
    Posts
    23

    Re: Using embedded DLL's/Extracting .ZIP's

    I do understand that for some more experienced VS2010 VB programmers, it would be easy to understand about passing streams to the dll, but I just recently got VS2010 and have never handled dll's before. I used to use VB6 to make very simple programs, and this is a big step for me. I would appreciate more simple help. 'pass the stream to the dll' is new for me, I have no clue how to do this. If you or anyone else can simplify this down for a beginner to understand, it would be a whole lot better for me to take in and learn.

    Thanks,

    -Conroy

  22. #22
    PowerPoster JuggaloBrotha's Avatar
    Join Date
    Sep 2005
    Location
    Lansing, MI; USA
    Posts
    4,286

    Re: Using embedded DLL's/Extracting .ZIP's

    You know how to pass something to another thing, in post #15 you posted your code:
    File.Extract("C:\Users\Dale\Desktop", ExtractExistingFileAction.OverwriteSilently)
    Where you're trying to pass "C:\Users\Dale\Desktop" and ExtractExistingFileAction.OverwriteSilently to the File.Extract method, which is in the dll. So instead of passing "C:\Users\Dale\Desktop" to it, pass it s (the stream) instead. Though it may be a different method call that takes the stream, which I couldn't tell you any more than that because I dont have the dll, I dont know what methods (and arguments) it takes. Someone would have to send me the dll before I could answer anything else at this point.
    Currently using VS 2015 Enterprise on Win10 Enterprise x64.

    CodeBank: All ThreadsColors ComboBoxFading & Gradient FormMoveItemListBox/MoveItemListViewMultilineListBoxMenuButtonToolStripCheckBoxStart with Windows

  23. #23

    Thread Starter
    Junior Member
    Join Date
    Jun 2010
    Posts
    23

    Re: Using embedded DLL's/Extracting .ZIP's

    Sent you a PM.

    The function is File.Extract(TargetDir, ExtractExistingFileAction.OverwriteSilently)

  24. #24
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: Using embedded DLL's/Extracting .ZIP's

    OK... there is a LOT of confusion here on what is what...

    http://dotnetzip.codeplex.com/

    The zipped file is in a resource, correct?
    OK.. so... what you need is to get a stream that contains the data of the resource, and feed it to the DotNetZip object that represents the zipped file. At this point, we aren't even to "File.Extract" level yet... so let's not worry about it.

    From the CodePlex page where the project is hosted, is this sample code:
    Code:
      Dim ZipToUnpack As String = "C1P3SML.zip"  
       Dim TargetDir As String = "C1P3SML"  
       Console.WriteLine("Extracting file {0} to {1}", ZipToUnpack, TargetDir)   
       Using zip1 As ZipFile = ZipFile.Read(ZipToUnpack)   
           AddHandler zip1.ExtractProgress, AddressOf MyExtractProgress   
           Dim e As ZipEntry   
           ' here, we extract every entry, but we could extract    
           ' based on entry name, size, date, etc.   
           For Each e In zip1   
               e.Extract(TargetDir, ExtractExistingFileAction.OverwriteSilently)   
           Next  
       End Using
    OK... so now, let's modify that to work with a stream. PLEASE NOTE: this is untested.
    vb Code:
    1. ' This creates the stream from the resource
    2. Using s As Stream = Me.GetType().Assembly.GetManifestResourceStream(Me.GetType(), "Conroy.zip")
    3.     Dim TargetDir As String = "C1P3SML"  'Naturally adjust this to suit your needs.
    4.    Using zip1 As ZipFile = ZipFile.Read(s)   'as Juggalo stated: Pass "s" to the zip dll thing
    5.        AddHandler zip1.ExtractProgress, AddressOf MyExtractProgress   ' I'm guessing this is optional if you want to show progress....
    6.        Dim e As ZipEntry  
    7.        ' here, we extract every entry, but we could extract    
    8.        ' based on entry name, size, date, etc.  
    9.        For Each e In zip1  
    10.            e.Extract(TargetDir, ExtractExistingFileAction.OverwriteSilently)   ' This is what will actually write your files out
    11.        Next  
    12.    End Using  'zip1
    13. End Using 'Stream

    By the time you get to File.Extract, you should have already read the stream to the archive file. The File.Extract has nothing to do with the stream by that point.

    -tg

    side note - took me less than 3 minutes to look all that info up and put it together. it isn't rocket science.
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  25. #25
    PowerPoster JuggaloBrotha's Avatar
    Join Date
    Sep 2005
    Location
    Lansing, MI; USA
    Posts
    4,286

    Re: Using embedded DLL's/Extracting .ZIP's

    conroy, I got your PM and what TG has already posted here is what I was talking about (even though I didn't have the actual dll, nor the codeplex website to reference)
    Currently using VS 2015 Enterprise on Win10 Enterprise x64.

    CodeBank: All ThreadsColors ComboBoxFading & Gradient FormMoveItemListBox/MoveItemListViewMultilineListBoxMenuButtonToolStripCheckBoxStart with Windows

  26. #26

    Thread Starter
    Junior Member
    Join Date
    Jun 2010
    Posts
    23

    Re: Using embedded DLL's/Extracting .ZIP's

    Finally, it works with that code. Hopefully I'll know in the future, thanks both of you.

    -Conroy

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width