473,387 Members | 1,798 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Adding DLL references to VB.Net Project

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
Nov 20 '05 #1
6 17113


Nov 20 '05 #2
* =?Utf-8?B?RGVubmlz?= <De****@discussions.microsoft.com> 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/>
Nov 20 '05 #3
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

Nov 20 '05 #4
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

Nov 20 '05 #5
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

Nov 20 '05 #6
Thanks for sharing this knowledge.

"Dennis" <De****@discussions.microsoft.com> schreef in bericht
news:18**********************************@microsof t.com...
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

Nov 21 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: filip stas | last post by:
How do i add references during runtime?
3
by: zfeld | last post by:
How do I add objects to a comboBox? What I need is something similar to what there was in MFC as MyObj obj; ComboBox cb; int index = cb.Add(obj.name); cb.AddItemData(&obj, index); Which...
10
by: Geoff Jones | last post by:
Hiya I hope somebody can help me with this relatively simple beginner question: I have created a windows Application in C#. I have also created a project, which includes a class. I have added...
1
by: caldera | last post by:
hi, I have a debug problem. I divide my web project into two part actually two project. One part is include the all of the logic class and other part web application part. These are two different...
3
by: _DS | last post by:
The two obvious methods for ref'ing assemblies are: Add a reference and 'Browse' for the actual DLL OR Add existing project to the solution, then add a ref to 'Project'. 1: I'd like to...
1
by: Andy | last post by:
Hi all, I have some projects where I actually don't want system.xml or system.data to be referenced from my project (because they are not to be used in this particular layer), but everytime I...
0
by: Maqsood Ahmed | last post by:
Hello, I have converted an application from .net 1.1 to .net 2.0. I added a Windows Installer project to the solution and all worked well. Now I want to bind the solution to source control (VSS...
1
by: Sala | last post by:
Hi creative thinkers ! I have one project in C# .. that project name ewaoNET . Now i will shifted into another project sub folders.... My current Project : Cititown Now i will use existing (...
0
by: Narasimham | last post by:
Hi, I was able to successfully create a new project using the devenv command line arguments. I did devenv /command np and then specified the name of the project and its location in the
1
by: waldo | last post by:
Hi there, I'm trying to create an ASP site in Visual Studio 2005 that needs to include some dlls that I have already written. The problem is that when I add a reference to a certain dll, i get...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.