DLLs

homebrew311

Active member
Joined
Oct 25, 2003
Messages
31
Every time I make a DLL and try to use it, the host program always returns a "Object reference not set to the instance of an object" error. What am I doing wrong?
 
Dll code
Code:
Public Class Class1
    Public Function Bob(ByVal int1 As Integer, ByVal int2 As Integer) As String
        Dim Ans As Integer
        Ans = int1 + int2
        Return Ans
    End Function
End Class

Button procedure
Code:
Private Sub btnStart_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnStart.Click
        Dim DLL As Dll_Test_Dll.Class1
        MsgBox(DLL.Bob(1, 2))
    End Sub
 
try the following...
Code:
Private Sub btnStart_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnStart.Click
        Dim DLL As New  Dll_Test_Dll.Class1    change this line
        MsgBox(DLL.Bob(1, 2))
    End Sub
 
you need the new keyword... at least in C# you would, probably the same for VB...

Dim DLL as New Dll_Test_Dll.Class1
 
And while youre at it, you may want to clean up Class1.Bob as well, because the signature claims to return a sting, but in the code you return an integer. :)
 
Back
Top