Can VB.Net DLL Have Specific Controls With No Form?

J

jean

I am very new to .Net and Visual Basic in general. My goal is to write
a Visual Basic .Net DLL that can have its functions and subroutines
called from another .Net application. My DLL will not have any kind of
user interface.

Can I use a Timer Control, A Winsock Control, and Serial Com Port class
(The reason I am using this class from some borrowed code, is that I
heard that .Net 1.1 does not have a built-in Serial Com Port
Communication class) in my DLL without using a form?

Thanks for any guidance on if this is even possible in .Net

Jean-Marie Vaneskahian
(e-mail address removed)
 
C

Cor Ligthert [MVP]

Jean,

A control has in Net two meanings, for most of us it is all that inherits
from "control" (either Webpage or Winform). For others it is as well a kind
of component as it is used in the toolbox (this misunderstanding is probably
because how Microsoft uses that toolbox and the way they describe it).

A (kind of) component can you use (almost) everywhere. A control you can of
course only use with a form. (While a windowforms timer can only be used
with a form, however there are two other timers that can be used on other
places).

I hope this helps,

Cor
 
M

Metallikanz!

Though I am not exactly sure of how thinks happen in vb.net, I more or less have a C# background, I would attempt to answer your question.

If the controls that you plan to use makes it a requirement that they be hosted on a windows form, you can add a form to your project and still compile the entire application as a .NET class library (.dll), you can keep this form hidden or something after you load it. And by the way the controls mentioned by you can also be used without adding them to a form:

dim oSocket as new WinSocketControl
..
..
..
oSocket.Listen()

HTH, Metallikanz!
 
J

jean

Here is a posting I made on the HomeSeer message board. I now have the
answers to many of my questions.

Guys thanks so much for the information. Since I posted this question I
have bought myself the two Wrox books on Visual Basic .Net (Beginning
and Programming). I have skipped around in the books looking for the
information I would need to build my code natively in .Net.

Through my previous experience with VB 6.0 writing an ActiveX
Executable that talked to HomeSeer 1.7 through COM and vice-versa, and
the answers to my questions here, I now have all the information I
need.

I do like the idea of writing my code as HomeSeer Plug-In since I would
be in the same "environment" as HomeSeer itself with all the
benefits that provides. Since my code will not have any kind of user
interface and I would just like to make this a .Net class, I would like
to write the code as a DLL.

The big three controls that I used to use were the MSComm Control,
Winsock Control and Timers on forms. I have learned the basics of all
three of these in .Net and how they would be imbedded in a .Net class
or as classes of their own called by my .Net class.

Here is what I have done for my three main components:

1. For serial port communications I am using the code posted here by
Rich. It is a .Net Class that looks like a wrapper for calls to the
Windows API. I have compiled the class called "clsRS232" as a DLL
in Visual Studio 2003. It seems to have the events and properties that
I will need, similar to the MSComm Control in Visual Basic 6.0.

2. For Winsock communications (specifically UDP) I have built my own
..Net class that I have compiled into a DLL. Here is the source code for
the class I wrote (it has an event and a few methods), it works great.


Code:
Imports System.Net.Sockets
Imports System.Text
Imports System.Threading
Public Class UDPData
Private ReceivingUDPObject As UdpClient
Private ThreadUDPReceive As System.Threading.Thread
Private RemoteIpEndPoint As New
System.Net.IPEndPoint(System.Net.IPAddress.Any, 0)
Public Event UDPMessageReceived(ByVal Message As String)
Public Sub SendDataViaUDP(ByVal LocalPort As Integer, ByVal
RemoteComputerAddress As String, ByVal RemoteComputerPort As Integer,
ByVal Message As String)
Dim UDPClientObject As New UdpClient(LocalPort)
UDPClientObject.Send(Encoding.ASCII.GetBytes(Message),
Encoding.ASCII.GetBytes(Message).Length, RemoteComputerAddress,
RemoteComputerPort)
UDPClientObject.Close()
UDPClientObject = Nothing
End Sub
Public Sub StartReceivingUDPData(ByVal ListenToPort As Integer)
ReceivingUDPObject = New System.Net.Sockets.UdpClient(ListenToPort)
ThreadUDPReceive = New System.Threading.Thread(AddressOf
ReceiveUDPMessages)
ThreadUDPReceive.Start()
End Sub
Public Sub StopReceivingUDPData()
ThreadUDPReceive.Abort()
ReceivingUDPObject.Close()
End Sub
Private Sub ReceiveUDPMessages()
Dim RawDataReceived As [Byte]() =
ReceivingUDPObject.Receive(RemoteIpEndPoint)
Dim StringReceived As String
StringReceived = Trim(Encoding.ASCII.GetChars(RawDataReceived))
RaiseEvent UDPMessageReceived(StringReceived)
StartNewUDPReceivingThread()
End Sub
Private Sub StartNewUDPReceivingThread()
ThreadUDPReceive = New System.Threading.Thread(AddressOf
ReceiveUDPMessages)
ThreadUDPReceive.Start()
End Sub
End Class


3. For timed events to fire off, I learned how to use timers in a
class. It is very different from the simple little timer control you
add to your forms in Visual Basic 6.0, but again they work just fine.


Code:
Private WithEvents TestTimer As Timers.Timer
Private Ticks As Integer

Sub Start_Timer()
TestTimer = Nothing
TestTimer = New Timers.Timer
TestTimer.Interval = 1000
TestTimer.Start()
End Sub

Private Sub TestTimer_Elapsed(ByVal sender As Object, ByVal e As
System.Timers.ElapsedEventArgs) Handles TestTimer.Elapsed
Console.WriteLine("Tick: " & Ticks)
Ticks += 1
If Ticks > 5 Then
Ticks = 0
TestTimer.Stop()
End If
End Sub


I have completely read the HomeSeer Plug-In SDK and think I understand
what I need to do. At the very least I can get my DLL working and then
deal with the HomeSeer Plug-In issues. I am curious, what is the
difference from an event that a .Net Class fires off and what HomeSeer
calls "Callbacks"? What are Callbacks and why do they have to be
registered and where would I use them? If my process does some
listening on the Serial port and some UDP messages with some looping,
when should I call the equivalent of DoEvents in .Net or use the new
"Threading"?

Thanks again for all your help, and any more guidance or suggestions
would be greatly appreciated!

Jean-Marie Vaneskahian
(e-mail address removed)
 

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