473,566 Members | 2,924 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 17137


Nov 20 '05 #2
* =?Utf-8?B?RGVubmlz?= <De****@discuss ions.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("zli b.DLL", EntryPoint:="co mpress", SetLastError:=T rue, CharSet:=CharSe t.Unicode, ExactSpelling:= True, _
CallingConventi on:=CallingConv ention.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(S ource 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("zli b.DLL", EntryPoint:="co mpress")> _
Private Shared Function CompressByteArr ay(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 CompressByteArr ay to compress in zlib.dLL
End Function
<DllImport("zli b.DLL", EntryPoint:="un compress")> _
Private Shared Function UncompressByteA rray(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 UnCompressByteA rray to Uncompress in zlib.dLL
End Function

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

Public Function CompressBytes(B yRef 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(Buff erSize)
'Compress data byte array
result = CompressByteArr ay(TempBuffer, BufferSize, Data, UBound(Data) + 1)
'Store results
If result = 0 Then
If usenewstorage Then
'Return results in TempBuffer
ReDim Preserve TempBuffer(Buff erSize - 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(Temp Buffer, 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(Buff ersize)

'Decompress data
result = UncompressByteA rray(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(Orig size - 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(Temp Buffer, 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("zli b.DLL", EntryPoint:="co mpress", SetLastError:=T rue, CharSet:=CharSe t.Unicode, ExactSpelling:= True, _
CallingConventi on:=CallingConv ention.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(S ource 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("zli b.DLL", EntryPoint:="co mpress")> _
Private Shared Function CompressByteArr ay(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 CompressByteArr ay to compress in zlib.dLL End Function
<DllImport("zli b.DLL", EntryPoint:="un compress")> _
Private Shared Function UncompressByteA rray(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 UnCompressByteA rray to Uncompress in zlib.dLL End Function

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

Public Function CompressBytes(B yRef 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(Buff erSize)
'Compress data byte array
result = CompressByteArr ay(TempBuffer, BufferSize, Data, UBound(Data) + 1) 'Store results
If result = 0 Then
If usenewstorage Then
'Return results in TempBuffer
ReDim Preserve TempBuffer(Buff erSize - 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(Temp Buffer, 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(Buff ersize)

'Decompress data
result = UncompressByteA rray(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(Orig size - 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(Temp Buffer, 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("zli b.DLL", EntryPoint:="co mpress", SetLastError:=T rue, CharSet:=CharSe t.Unicode, ExactSpelling:= True, _ CallingConventi on:=CallingConv ention.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****@discuss ions.microsoft. com> schreef in bericht
news:18******** *************** ***********@mic rosoft.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(S ource 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("zli b.DLL", EntryPoint:="co mpress")> _
Private Shared Function CompressByteArr ay(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
CompressByteArr ay to compress in zlib.dLL
End Function
<DllImport("zli b.DLL", EntryPoint:="un compress")> _
Private Shared Function UncompressByteA rray(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
UnCompressByteA rray to Uncompress in zlib.dLL
End Function

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

Public Function CompressBytes(B yRef 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(Buff erSize)
'Compress data byte array
result = CompressByteArr ay(TempBuffer, BufferSize, Data,
UBound(Data) + 1)
'Store results
If result = 0 Then
If usenewstorage Then
'Return results in TempBuffer
ReDim Preserve TempBuffer(Buff erSize - 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(Temp Buffer, 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(Buff ersize)

'Decompress data
result = UncompressByteA rray(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(Orig size - 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(Temp Buffer, 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("zli b.DLL", EntryPoint:="co mpress", SetLastError:=T rue,
CharSet:=CharSe t.Unicode, ExactSpelling:= True, _
CallingConventi on:=CallingConv ention.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
6576
by: filip stas | last post by:
How do i add references during runtime?
3
11218
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 can then be retrieved as:
10
1144
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 the project to the main application but I can't seem to create an instance of the class in the main application. The class is called MyFirstClass,...
1
1218
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 projects. I add the dll of the first part to web part as a references. But then I can't debug the first part while I run the web part. It said that...
3
1987
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 find out what the latter method is doing. I'm assuming that it makes sure that debug exe gets matched to
1
1168
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 add a new file to the project, studio keeps adding them back in! Any way to stop this? Thanks
0
984
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 2005). It uploaded all files/project but the installer project. There is no right click option for it either. Am I missing a trick here? Please...
1
2664
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 ( ewaoNet ) project in to Dating folder... This ewaoNET project using custom controls so i will use this functionalities also within in cititown project
0
614
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
1168
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 "The specified module could not be found (Exception from HRESULT: 0x8007007E)" when i try to build. I am not sure which dll is causing it because one...
0
7673
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
8109
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7645
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7953
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
1
5485
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3643
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3626
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2085
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1202
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.