PC Review


Reply
Thread Tools Rate Thread

Adding DLL references to VB.Net Project

 
 
=?Utf-8?B?RGVubmlz?=
Guest
Posts: n/a
 
      11th Jul 2004
I am trying to use ZLIB.Dll in a VB.Net project but keep getting an error message that says it can't load the DLL. I tried to add a reference using "Project-Add Reference" but get the error message stating it's not a valid Com component. I'm new to vb.net so any help would be appreciated. Thanks.
--
Dennis in Houston
 
Reply With Quote
 
 
 
 
Herfried K. Wagner [MVP]
Guest
Posts: n/a
 
      11th Jul 2004
* =?Utf-8?B?RGVubmlz?= <(E-Mail Removed)> scripsit:
> I am trying to use ZLIB.Dll in a VB.Net project but keep getting an
> error message that says it can't load the DLL.


That's because "ZLIB.DLL" is a "standard DLL", which exports functions,
and it's no .NET assembly or COM DLL. Instead of referencing it, you
can use the functions by declaring them ('Declare', 'DllImport', see
chapters about platform invocation in help).

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
 
Reply With Quote
 
=?Utf-8?B?RGVubmlz?=
Guest
Posts: n/a
 
      11th Jul 2004
Thanks to help from Cor and Herfried, I got it to work as follows:

<DllImport("zlib.DLL", EntryPoint:="compress", SetLastError:=True, CharSet:=CharSet.Unicode, ExactSpelling:=True, _
CallingConvention:=CallingConvention.StdCall)> _
Public Shared Function compressv(ByVal dest As Byte(), ByRef destLen As Integer, ByVal src As Byte(), ByVal srcLen As Integer) As Integer
' Leave function empty - DLLImport attribute forwards calls to compressv to
' compress in zlib.dLL
End Function

After this declaration, you can use normal calling conventions to compressV by specifying byte arrays, integers, etc. Since in VB.Net, a delcare statement for an unmanaged DLL invokes dllimport, I don't understand why M'soft didn't allow standard calling conventions in the Declare statements. But anyway, it works now. Thanks to help I got.
--
Dennis in Houston


"Dennis" wrote:

> I am trying to use ZLIB.Dll in a VB.Net project but keep getting an error message that says it can't load the DLL. I tried to add a reference using "Project-Add Reference" but get the error message stating it's not a valid Com component. I'm new to vb.net so any help would be appreciated. Thanks.
> --
> Dennis in Houston

 
Reply With Quote
 
=?Utf-8?B?RGVubmlz?=
Guest
Posts: n/a
 
      11th Jul 2004
For all the newcomers to VB.Net (I know this is simple stuff to experienced users), below is a class in VB that compresses and decompresses byte arrrays. Thanks to all the help from other users.

'DATACOMPRESS CLASS - VB.Net
'**********************************************************************************************************
' METHODS:
' CompressBytes(Source ByteArray, Optional Temporay Byte Array
' Compresses ByteArray into Temporary Byte Array or into ByteArray if Temporary Byte Array not input
'
' DeCompressBytes (Source ByteArray, Original Array Size before compression as integer, Optional Temporary Byte Array)
' Decompresses ByteArray into Temporary Byte Array or into ByteArray if Temporary Byte Array not input
'
'***********************************************************************************************************
Imports System.Runtime.InteropServices

Public Class DataCompress

'Declare zlib functions "Compress" and "Uncompress" for compressing Byte Arrays
<DllImport("zlib.DLL", EntryPoint:="compress")> _
Private Shared Function CompressByteArray(ByVal dest As Byte(), ByRef destLen As Integer, ByVal src As Byte(), ByVal srcLen As Integer) As Integer
' Leave function empty - DLLImport attribute forwards calls to CompressByteArray to compress in zlib.dLL
End Function
<DllImport("zlib.DLL", EntryPoint:="uncompress")> _
Private Shared Function UncompressByteArray(ByVal dest As Byte(), ByRef destLen As Integer, ByVal src As Byte(), ByVal srcLen As Integer) As Integer
' Leave function empty - DLLImport attribute forwards calls to UnCompressByteArray to Uncompress in zlib.dLL
End Function

Public Sub New()
MyBase.New()
End Sub

Public Function CompressBytes(ByRef Data() As Byte, Optional ByRef TempBuffer() As Byte = Nothing) As Integer
'Compresses Data into a temp buffer
'Returns compressed Data in Data if TempBuff not specified
'Returns Result = Size of compressed data if ok, -1 if not
Dim OriginalSize As Long = UBound(Data) + 1
'Allocate temporary Byte Array for storage
Dim result As Integer
Dim usenewstorage As Boolean
If TempBuffer Is Nothing Then usenewstorage = False Else usenewstorage = True
Dim BufferSize As Integer = UBound(Data) + 1
BufferSize = CInt(BufferSize + (BufferSize * 0.01) + 12)
ReDim TempBuffer(BufferSize)
'Compress data byte array
result = CompressByteArray(TempBuffer, BufferSize, Data, UBound(Data) + 1)
'Store results
If result = 0 Then
If usenewstorage Then
'Return results in TempBuffer
ReDim Preserve TempBuffer(BufferSize - 1)
Else
'Return compressed Data in original Data Array
' Resize original data array to compressed size
ReDim Data(BufferSize - 1)
' Copy Array to original data array
Array.Copy(TempBuffer, Data, BufferSize)
'Release TempBuffer STorage
TempBuffer = Nothing
End If
Return BufferSize
Else
Return -1
End If
End Function
Public Function DeCompressBytes(ByRef Data() As Byte, ByVal Origsize As Integer, Optional ByRef TempBuffer() As Byte = Nothing) As Integer
'DeCompresses Data into a temp buffer..note that Origsize must be the size of the original data before compression
'Returns compressed Data in Data if TempBuff not specified
'Returns Result = Size of decompressed data if ok, -1 if not
'Allocate memory for buffers
Dim result As Integer
Dim usenewstorage As Boolean
Dim Buffersize As Integer = CInt(Origsize + (Origsize * 0.01) + 12)
If TempBuffer Is Nothing Then usenewstorage = False Else usenewstorage = True
ReDim TempBuffer(Buffersize)

'Decompress data
result = UncompressByteArray(TempBuffer, Origsize, Data, UBound(Data) + 1)

'Truncate buffer to compressed size
If result = 0 Then
If usenewstorage Then
'Return decoompressed data in TempBuffer
ReDim Preserve TempBuffer(Origsize - 1)
Else
'Return decompressed data in original source data file
' Truncate to compressed size
ReDim Data(Origsize - 1)
' Copy Array to original data array
Array.Copy(TempBuffer, Data, Origsize)
'Release TempBuffer STorage
TempBuffer = Nothing
End If
Return Origsize
Else
Return -1
End If
End Function


Protected Overrides Sub Finalize()
MyBase.Finalize()
End Sub

End Class

--
Dennis in Houston


"Dennis" wrote:

> Thanks to help from Cor and Herfried, I got it to work as follows:
>
> <DllImport("zlib.DLL", EntryPoint:="compress", SetLastError:=True, CharSet:=CharSet.Unicode, ExactSpelling:=True, _
> CallingConvention:=CallingConvention.StdCall)> _
> Public Shared Function compressv(ByVal dest As Byte(), ByRef destLen As Integer, ByVal src As Byte(), ByVal srcLen As Integer) As Integer
> ' Leave function empty - DLLImport attribute forwards calls to compressv to
> ' compress in zlib.dLL
> End Function
>
> After this declaration, you can use normal calling conventions to compressV by specifying byte arrays, integers, etc. Since in VB.Net, a delcare statement for an unmanaged DLL invokes dllimport, I don't understand why M'soft didn't allow standard calling conventions in the Declare statements. But anyway, it works now. Thanks to help I got.
> --
> Dennis in Houston
>
>
> "Dennis" wrote:
>
> > I am trying to use ZLIB.Dll in a VB.Net project but keep getting an error message that says it can't load the DLL. I tried to add a reference using "Project-Add Reference" but get the error message stating it's not a valid Com component. I'm new to vb.net so any help would be appreciated. Thanks.
> > --
> > Dennis in Houston

 
Reply With Quote
 
Cor Ligthert
Guest
Posts: n/a
 
      11th Jul 2004
Hi Dennis,

Thanks for sharing this with the newgroups
I added Zip file in the header than it will be easy to find on Google.

Cor

> For all the newcomers to VB.Net (I know this is simple stuff to

experienced users), below is a class in VB that compresses and decompresses
byte arrrays. Thanks to all the help from other users.
>
> 'DATACOMPRESS CLASS - VB.Net
>

'***************************************************************************
*******************************
> ' METHODS:
> ' CompressBytes(Source ByteArray, Optional Temporay Byte Array
> ' Compresses ByteArray into Temporary Byte Array or into

ByteArray if Temporary Byte Array not input
> '
> ' DeCompressBytes (Source ByteArray, Original Array Size before

compression as integer, Optional Temporary Byte Array)
> ' Decompresses ByteArray into Temporary Byte Array or into

ByteArray if Temporary Byte Array not input
> '
>

'***************************************************************************
********************************
> Imports System.Runtime.InteropServices
>
> Public Class DataCompress
>
> 'Declare zlib functions "Compress" and "Uncompress" for compressing

Byte Arrays
> <DllImport("zlib.DLL", EntryPoint:="compress")> _
> Private Shared Function CompressByteArray(ByVal dest As Byte(), ByRef

destLen As Integer, ByVal src As Byte(), ByVal srcLen As Integer) As Integer
> ' Leave function empty - DLLImport attribute forwards calls to

CompressByteArray to compress in zlib.dLL
> End Function
> <DllImport("zlib.DLL", EntryPoint:="uncompress")> _
> Private Shared Function UncompressByteArray(ByVal dest As Byte(), ByRef

destLen As Integer, ByVal src As Byte(), ByVal srcLen As Integer) As Integer
> ' Leave function empty - DLLImport attribute forwards calls to

UnCompressByteArray to Uncompress in zlib.dLL
> End Function
>
> Public Sub New()
> MyBase.New()
> End Sub
>
> Public Function CompressBytes(ByRef Data() As Byte, Optional ByRef

TempBuffer() As Byte = Nothing) As Integer
> 'Compresses Data into a temp buffer
> 'Returns compressed Data in Data if TempBuff not specified
> 'Returns Result = Size of compressed data if ok, -1 if not
> Dim OriginalSize As Long = UBound(Data) + 1
> 'Allocate temporary Byte Array for storage
> Dim result As Integer
> Dim usenewstorage As Boolean
> If TempBuffer Is Nothing Then usenewstorage = False Else

usenewstorage = True
> Dim BufferSize As Integer = UBound(Data) + 1
> BufferSize = CInt(BufferSize + (BufferSize * 0.01) + 12)
> ReDim TempBuffer(BufferSize)
> 'Compress data byte array
> result = CompressByteArray(TempBuffer, BufferSize, Data,

UBound(Data) + 1)
> 'Store results
> If result = 0 Then
> If usenewstorage Then
> 'Return results in TempBuffer
> ReDim Preserve TempBuffer(BufferSize - 1)
> Else
> 'Return compressed Data in original Data Array
> ' Resize original data array to compressed size
> ReDim Data(BufferSize - 1)
> ' Copy Array to original data array
> Array.Copy(TempBuffer, Data, BufferSize)
> 'Release TempBuffer STorage
> TempBuffer = Nothing
> End If
> Return BufferSize
> Else
> Return -1
> End If
> End Function
> Public Function DeCompressBytes(ByRef Data() As Byte, ByVal Origsize

As Integer, Optional ByRef TempBuffer() As Byte = Nothing) As Integer
> 'DeCompresses Data into a temp buffer..note that Origsize must be

the size of the original data before compression
> 'Returns compressed Data in Data if TempBuff not specified
> 'Returns Result = Size of decompressed data if ok, -1 if not
> 'Allocate memory for buffers
> Dim result As Integer
> Dim usenewstorage As Boolean
> Dim Buffersize As Integer = CInt(Origsize + (Origsize * 0.01) +

12)
> If TempBuffer Is Nothing Then usenewstorage = False Else

usenewstorage = True
> ReDim TempBuffer(Buffersize)
>
> 'Decompress data
> result = UncompressByteArray(TempBuffer, Origsize, Data,

UBound(Data) + 1)
>
> 'Truncate buffer to compressed size
> If result = 0 Then
> If usenewstorage Then
> 'Return decoompressed data in TempBuffer
> ReDim Preserve TempBuffer(Origsize - 1)
> Else
> 'Return decompressed data in original source data file
> ' Truncate to compressed size
> ReDim Data(Origsize - 1)
> ' Copy Array to original data array
> Array.Copy(TempBuffer, Data, Origsize)
> 'Release TempBuffer STorage
> TempBuffer = Nothing
> End If
> Return Origsize
> Else
> Return -1
> End If
> End Function
>
>
> Protected Overrides Sub Finalize()
> MyBase.Finalize()
> End Sub
>
> End Class
>
> --
> Dennis in Houston
>
>
> "Dennis" wrote:
>
> > Thanks to help from Cor and Herfried, I got it to work as follows:
> >
> > <DllImport("zlib.DLL", EntryPoint:="compress", SetLastError:=True,

CharSet:=CharSet.Unicode, ExactSpelling:=True, _
> > CallingConvention:=CallingConvention.StdCall)> _
> > Public Shared Function compressv(ByVal dest As Byte(), ByRef destLen As

Integer, ByVal src As Byte(), ByVal srcLen As Integer) As Integer
> > ' Leave function empty - DLLImport attribute forwards calls to

compressv to
> > ' compress in zlib.dLL
> > End Function
> >
> > After this declaration, you can use normal calling conventions to

compressV by specifying byte arrays, integers, etc. Since in VB.Net, a
delcare statement for an unmanaged DLL invokes dllimport, I don't understand
why M'soft didn't allow standard calling conventions in the Declare
statements. But anyway, it works now. Thanks to help I got.
> > --
> > Dennis in Houston
> >
> >
> > "Dennis" wrote:
> >
> > > I am trying to use ZLIB.Dll in a VB.Net project but keep getting an

error message that says it can't load the DLL. I tried to add a reference
using "Project-Add Reference" but get the error message stating it's not a
valid Com component. I'm new to vb.net so any help would be appreciated.
Thanks.
> > > --
> > > Dennis in Houston



 
Reply With Quote
 
Marcel
Guest
Posts: n/a
 
      18th Dec 2004
Thanks for sharing this knowledge.

"Dennis" <(E-Mail Removed)> schreef in bericht
news:1875CD06-EF8C-40DE-BFA4-(E-Mail Removed)...
> For all the newcomers to VB.Net (I know this is simple stuff to
> experienced users), below is a class in VB that compresses and
> decompresses byte arrrays. Thanks to all the help from other users.
>
> 'DATACOMPRESS CLASS - VB.Net
> '**********************************************************************************************************
> ' METHODS:
> ' CompressBytes(Source ByteArray, Optional Temporay Byte Array
> ' Compresses ByteArray into Temporary Byte Array or into
> ByteArray if Temporary Byte Array not input
> '
> ' DeCompressBytes (Source ByteArray, Original Array Size before
> compression as integer, Optional Temporary Byte Array)
> ' Decompresses ByteArray into Temporary Byte Array or into
> ByteArray if Temporary Byte Array not input
> '
> '***********************************************************************************************************
> Imports System.Runtime.InteropServices
>
> Public Class DataCompress
>
> 'Declare zlib functions "Compress" and "Uncompress" for compressing
> Byte Arrays
> <DllImport("zlib.DLL", EntryPoint:="compress")> _
> Private Shared Function CompressByteArray(ByVal dest As Byte(), ByRef
> destLen As Integer, ByVal src As Byte(), ByVal srcLen As Integer) As
> Integer
> ' Leave function empty - DLLImport attribute forwards calls to
> CompressByteArray to compress in zlib.dLL
> End Function
> <DllImport("zlib.DLL", EntryPoint:="uncompress")> _
> Private Shared Function UncompressByteArray(ByVal dest As Byte(), ByRef
> destLen As Integer, ByVal src As Byte(), ByVal srcLen As Integer) As
> Integer
> ' Leave function empty - DLLImport attribute forwards calls to
> UnCompressByteArray to Uncompress in zlib.dLL
> End Function
>
> Public Sub New()
> MyBase.New()
> End Sub
>
> Public Function CompressBytes(ByRef Data() As Byte, Optional ByRef
> TempBuffer() As Byte = Nothing) As Integer
> 'Compresses Data into a temp buffer
> 'Returns compressed Data in Data if TempBuff not specified
> 'Returns Result = Size of compressed data if ok, -1 if not
> Dim OriginalSize As Long = UBound(Data) + 1
> 'Allocate temporary Byte Array for storage
> Dim result As Integer
> Dim usenewstorage As Boolean
> If TempBuffer Is Nothing Then usenewstorage = False Else
> usenewstorage = True
> Dim BufferSize As Integer = UBound(Data) + 1
> BufferSize = CInt(BufferSize + (BufferSize * 0.01) + 12)
> ReDim TempBuffer(BufferSize)
> 'Compress data byte array
> result = CompressByteArray(TempBuffer, BufferSize, Data,
> UBound(Data) + 1)
> 'Store results
> If result = 0 Then
> If usenewstorage Then
> 'Return results in TempBuffer
> ReDim Preserve TempBuffer(BufferSize - 1)
> Else
> 'Return compressed Data in original Data Array
> ' Resize original data array to compressed size
> ReDim Data(BufferSize - 1)
> ' Copy Array to original data array
> Array.Copy(TempBuffer, Data, BufferSize)
> 'Release TempBuffer STorage
> TempBuffer = Nothing
> End If
> Return BufferSize
> Else
> Return -1
> End If
> End Function
> Public Function DeCompressBytes(ByRef Data() As Byte, ByVal Origsize As
> Integer, Optional ByRef TempBuffer() As Byte = Nothing) As Integer
> 'DeCompresses Data into a temp buffer..note that Origsize must be
> the size of the original data before compression
> 'Returns compressed Data in Data if TempBuff not specified
> 'Returns Result = Size of decompressed data if ok, -1 if not
> 'Allocate memory for buffers
> Dim result As Integer
> Dim usenewstorage As Boolean
> Dim Buffersize As Integer = CInt(Origsize + (Origsize * 0.01) + 12)
> If TempBuffer Is Nothing Then usenewstorage = False Else
> usenewstorage = True
> ReDim TempBuffer(Buffersize)
>
> 'Decompress data
> result = UncompressByteArray(TempBuffer, Origsize, Data,
> UBound(Data) + 1)
>
> 'Truncate buffer to compressed size
> If result = 0 Then
> If usenewstorage Then
> 'Return decoompressed data in TempBuffer
> ReDim Preserve TempBuffer(Origsize - 1)
> Else
> 'Return decompressed data in original source data file
> ' Truncate to compressed size
> ReDim Data(Origsize - 1)
> ' Copy Array to original data array
> Array.Copy(TempBuffer, Data, Origsize)
> 'Release TempBuffer STorage
> TempBuffer = Nothing
> End If
> Return Origsize
> Else
> Return -1
> End If
> End Function
>
>
> Protected Overrides Sub Finalize()
> MyBase.Finalize()
> End Sub
>
> End Class
>
> --
> Dennis in Houston
>
>
> "Dennis" wrote:
>
>> Thanks to help from Cor and Herfried, I got it to work as follows:
>>
>> <DllImport("zlib.DLL", EntryPoint:="compress", SetLastError:=True,
>> CharSet:=CharSet.Unicode, ExactSpelling:=True, _
>> CallingConvention:=CallingConvention.StdCall)> _
>> Public Shared Function compressv(ByVal dest As Byte(), ByRef destLen As
>> Integer, ByVal src As Byte(), ByVal srcLen As Integer) As Integer
>> ' Leave function empty - DLLImport attribute forwards calls to
>> compressv to
>> ' compress in zlib.dLL
>> End Function
>>
>> After this declaration, you can use normal calling conventions to
>> compressV by specifying byte arrays, integers, etc. Since in VB.Net, a
>> delcare statement for an unmanaged DLL invokes dllimport, I don't
>> understand why M'soft didn't allow standard calling conventions in the
>> Declare statements. But anyway, it works now. Thanks to help I got.
>> --
>> Dennis in Houston
>>
>>
>> "Dennis" wrote:
>>
>> > I am trying to use ZLIB.Dll in a VB.Net project but keep getting an
>> > error message that says it can't load the DLL. I tried to add a
>> > reference using "Project-Add Reference" but get the error message
>> > stating it's not a valid Com component. I'm new to vb.net so any help
>> > would be appreciated. Thanks.
>> > --
>> > Dennis in Houston



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Adding References to a Project ManicMiner17 Microsoft Excel Discussion 2 13th Feb 2011 03:40 PM
Adding references in Access project Marc Microsoft Access Form Coding 4 24th Mar 2009 04:36 AM
Dynammically adding project references into the webproject. Anubhav Jain Microsoft Dot NET Framework Forms 0 17th Apr 2006 03:40 PM
Dynammically adding project references into the webproject. Anubhav Jain Microsoft C# .NET 0 17th Apr 2006 03:40 PM
automatically including other references when adding a DLL to a project Bob Microsoft VB .NET 4 28th Aug 2003 12:48 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 01:55 AM.